Sai Kumar
Sai Kumar

Reputation: 9

Parse Notification works on emulator but not working on real device

I am working on Parse notifications..to send notifications to all users...The below code works well on emulator but the real device cannot get notifications.... Heres my code : MainActivity.java

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ParseAnalytics.trackAppOpenedInBackground(getIntent());
    PushService.setDefaultPushCallback(this, MainActivity.class);
    ParseInstallation.getCurrentInstallation().saveInBackground();
     }
     }

ParseApplication.java

public class ParseApplication extends Application{

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    Parse.initialize(this, "[APP ID]", "[CLIENT KEY]");
    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);



    ParseInstallation.getCurrentInstallation().saveInBackground();
   }

Receiver.java

public class Receiver extends ParsePushBroadcastReceiver{

@Override
protected void onPushOpen(Context arg0, Intent arg1) {
    // TODO Auto-generated method stub
    Intent i = new Intent(arg0,MainActivity.class);
    i.putExtras(arg1.getExtras());
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    arg0.startActivity(i);

}

AndroidManifest.xml

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="11" />
 <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.WAKE_LOCK"/>
  <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.example.parse.permission.C2D_MESSAGE" />
  <uses-permission android:name="com.example.parse.permission.C2D_MESSAGE" />
  <application
    android:allowBackup="true"
    android:name="com.example.parse.ParseApplication" 
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    >
    <activity
        android:name="com.example.parse.MainActivity"
        android:label="@string/app_name" >
        <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.example.parse.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>


  </application>

 </manifest>

Upvotes: 0

Views: 746

Answers (1)

bond
bond

Reputation: 11346

You do not have subscription set. If you haven't seen it already please follow the link. Parse Android Push Tutorial

In your Application onCreate:

ParsePush.subscribeInBackground("", new SaveCallback() {
  @Override
  public void done(ParseException e) {
    if (e == null) {
      Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
    } else {
      Log.e("com.parse.push", "failed to subscribe for push", e);
    }
  }
});

As you may be creating your own sample app, pay close attention to the Manifest configuration, ensure you have right package names. As noted in the Parse docs, they use GCM when Play-Services is available, which actual Android device will have. Where as they use persistent connection on devices without play-service ie. your emulator. Hope this helps.

Upvotes: 0

Related Questions