android - Parse Notification works on emulator but not working on real device -
i working on parse notifications..to send notifications users...the below code works on emulator real device cannot notifications.... heres 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 = 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>
you not have subscription set. if haven't seen please follow link. parse android push tutorial
in application oncreate:
parsepush.subscribeinbackground("", new savecallback() { @override public void done(parseexception e) { if (e == null) { log.d("com.parse.push", "successfully subscribed broadcast channel."); } else { log.e("com.parse.push", "failed subscribe push", e); } } });
as may creating own sample app, pay close attention manifest configuration, ensure have right package names. noted in parse docs, use gcm when play-services available, actual android device have. use persistent connection on devices without play-service ie. emulator. hope helps.
Comments
Post a Comment