我使用parse.com创建了简单的推送通知应用程序。
设备在parse.com上成功注册,但是当我尝试通过parse.com发送推送通知时,没有任何通知。
AndroidMainifest.xml代码:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</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" />
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />
接收人代码:
public class Receiver extends ParsePushBroadcastReceiver {
private Intent parseIntent;
public Receiver() {
super();
}
@Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
if (intent == null)
return;
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
parseIntent = intent;
} catch (JSONException e) {
Log.d("PushJsonException", "" + e.getMessage());
}
}
}
MainActivity Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Call Methods to Update Your Stuff
}
};
@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter("com.example.harrypotter.pushnotificationdemo"));
}
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
}
申请类:
public class ParseApp extends Application {
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
答案 0 :(得分:0)
Parse.com托管服务将于2017年1月28日完全退休。如果您有现有应用程序,请参阅此link并创建您自己的推送通知服务器。 Parse发布了一个数据库迁移工具,可以将数据从Parse应用程序迁移到任何MongoDB数据库。
更多信息请查看LInk
答案 1 :(得分:0)
您尚未更改清单文件中的“类别”属性:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
重要提示:在下面的行中更改“com.parse.starter.permission.C2D_MESSAGE” 匹配您的应用程序包名称+“。permission.C2D_MESSAGE”。
<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" />
<category android:name="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />