我已经成功创建了一个Parse应用程序,并且我在Android应用程序实现中使用了应用程序密钥。我已按照此处的所有步骤https://www.parse.com/apps/quickstart?onboard=#parse_push/android/existing (不幸需要注册,但这是一个即时流程)当我发送测试推送通知时,它会从仪表板发送,甚至被收到我将虚拟设备设置为控件,但物理设备上没有任何操作。我认为这可能是一个套接字问题所以我在wifi和3G连接之间交替没有成功
这是我正在使用的代码:
主:
package com.wetu.chronicle;
import android.os.Bundle;
import org.apache.cordova.*;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class chronicle extends DroidGap
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl(Config.getStartUrl());
Parse.initialize(this, "xxxxxxxxx", "yyyyyyyyyyyy");
PushService.setDefaultPushCallback(this, chronicle.class);
PushService.subscribe(this, "Newsfeed", chronicle.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Android Manifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.wetu.chronicle.permission.C2D_MESSAGE" />
<uses-permission android:name="com.wetu.chronicle.permission.C2D_MESSAGE" />
<application
android:debuggable="false"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name" tools:ignore="HardcodedDebugMode">
<activity android:name="chronicle" android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.wetu.chronicle" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/>
我可以澄清您可能遇到的任何问题和/或发布其他代码。
答案 0 :(得分:1)
最有可能的原因是您的应用在后台无效。很多我的Android应用程序一直在努力解决这个问题。一个不错的解决方案可能是确保有一个唤醒应用程序的闹钟。我从来没有处理解析,所以这可能不起作用,但它在其他情况下对我有用