我在android中创建了一个聊天应用程序。它工作正常。通知也在模拟器上运行。但是当我在设备上尝试时,似乎没有收到通知。我按照关于Android的解析教程进行了消息和通知,但仍然在设备上没有通知。指导我的相同。
我的清单文件具有以下权限:
package="com.gestureMsg.messenger"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.gestureMsg.messenger.permission.C2D_MESSAGE" />
<uses-permission android:name="com.gestureMsg.messenger.permission.C2D_MESSAGE" />
<application
android:name="packgest.MessengerApplication"
android:allowBackup="true"
android:icon="@drawable/msg"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:1076345567071" />;
<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/msg"/>
<activity android:name="packgest.MainActivity" android:screenOrientation="portrait">
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="packgest.CurrentUserActivity" android:screenOrientation="portrait"></activity>
<activity android:name="packgest.NewUserActivity" android:screenOrientation="portrait"></activity>
<activity android:name="packgest.ShowContactsWithApp" android:screenOrientation="portrait"></activity>
<activity android:name="packgest.ViewProfileActivity" android:screenOrientation="portrait"></activity>
<activity android:name="packgest.RefreshActivity" android:screenOrientation="portrait"></activity>
<activity android:name="packgest.AfterNotificationActivity" android:screenOrientation="portrait"></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.ParsePushBroadcastReceiver" android:exported="false"> -->
<receiver android:name="packgest.Reciever" 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.gestureMsg.messenger" />
</intent-filter>
</receiver>
</application>
我的推送代码是:
// Notification for Android users
ParsePush androidPush = new ParsePush();
androidPush.setMessage(currentUser.getUsername());
androidPush.setQuery(query);
androidPush.sendInBackground();`
我的应用类代码:
public class MessengerApplication extends Application {
private final static String APP_ID="xxx";
private final static String CLIENT_KEY ="xxx";
@Override
public void onCreate() {
// TODO Auto-generated method stub
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(getApplicationContext(),APP_ID,CLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
// the channel "" is called the "broadcast" channel and is used for broadly applicable messages
ParsePush.subscribeInBackground("", new SaveCallback()
{
@Override
public void done(ParseException e)
{
if (e == null)
{
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
System.out.println("successfully subscribed to the broadcast channel.");
}
else
{
Log.e("com.parse.push", "failed to subscribe for push", e);
System.out.println("failed to subscribe for push."+e.getMessage());
}
}
});
PushService.setDefaultPushCallback(this, CurrentUserActivity.class);
super.onCreate();
}
}