我已经查看了很多问题,但我没有得到任何推送通知。 我已添加所有权限并具有简单的接收器。当我调试时,它显示设备令牌为空。在解析时,检测到设备并且通知被标记为已发送但未在我的设备中接收。 我正在分享代码
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Parse.initialize(this, "", "");
}
catch (Exception e){
e.printStackTrace();
}
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
Log.e("Tag 1", e == null ? "Succeed to register the app" : "Failed to register the app", e);
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
Log.d("Tag 2", "Device token: " + deviceToken);
}
});
清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.arpan.push_notifivations">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:protectionLevel="signature"
android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.arpan.push_notifivations.MainActivity">
<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.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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.example.arpan.push_notifivations" />
</intent-filter>
</receiver>
</application>
</manifest>
我添加的依赖项是
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'