Parse Push Notification just work in Emulator

2019-02-27 08:31发布

问题:

I need help, because I am working with Parse Push Notification Android but my application just receives notifications in emulator but not receives in real devices.

In my analytics appears register.

This is my permission and BroadcastReceiver:

<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.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" />

<permission android:protectionLevel="signature"
    android:name="org.example.promociones.permission.C2D_MESSAGE" />
<uses-permission android:name="org.example.promociones.permission.C2D_MESSAGE" />

 <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.example.promociones.Receiver"
      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>

And my code of registration:

Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();

    Parse.initialize(this, "SomeValue",   "SomeValue");
    ParseInstallation.getCurrentInstallation().saveInBackground();
    ParsePush.subscribeInBackground("pruebas", new SaveCallback() {

        @Override
        public void done(com.parse.ParseException e) {
            // TODO Auto-generated method stub

            if(e!=null)
            {
                Log.d("com.parse.push", "La subscripcion al canal fue exitosa");
            }
            else
            {
                Log.e("com.parse.push", "Fallo la subscripcion push");
            }

        }
    });
}

回答1:

use the following instead:

    // inform the Parse Cloud that it is ready for notifications
    PushService.setDefaultPushCallback(this, MainActivity.class);   
    ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {

            } else {
                e.printStackTrace();

            }
        }
    });


回答2:

i had the same problem and it was because i didn't check package name

<permission
    android:name="YOUR_PACKAGE.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" />