android - parse does not push notifications but it shows registered users -
the parse not push notifications users. shows registered users in site.
here's 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); } }
parseapplication.java
public class parseapplication extends application{ @override public void oncreate() { // todo auto-generated method stub super.oncreate(); parse.initialize(this, "xxxx", "xxxx"); parseinstallation.getcurrentinstallation().saveinbackground(); } }
parsereceiver.java
public class parsereceiver extends broadcastreceiver{ private final string tag = "parse notification"; private string msg = ""; @override public void onreceive(context arg0, intent arg1) { // todo auto-generated method stub log.i(tag, "push received!!!"); try { string action = arg1.getaction(); string channel = arg1.getextras().getstring("com.parse.channel"); jsonobject json = new jsonobject(arg1.getextras().getstring("com.parse.data")); log.d(tag, "got action " + action + " on channel " + channel + " with:"); iterator itr = json.keys(); while (itr.hasnext()) { string key = (string) itr.next(); log.d(tag, "..." + key + " => " + json.getstring(key)); if(key.equals("string")){ msg = json.getstring(key); } } } catch (jsonexception e) { log.d(tag, "jsonexception: " + e.getmessage()); } bitmap icon = bitmapfactory.decoderesource(arg0.getresources(), r.drawable.happy); intent launchactivity = new intent(arg0, mainactivity.class); pendingintent pi = pendingintent.getactivity(arg0, 0, launchactivity, 0); notification noti = new notificationcompat.builder(arg0) .setcontenttitle("push received") .setcontenttext(msg) .setsmallicon(r.drawable.happy) .setlargeicon(icon) .setcontentintent(pi) .setautocancel(true) .build(); notificationmanager nm = (notificationmanager)arg0.getsystemservice(context.notification_service); nm.notify(0, noti); } }
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
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.parse" android:versioncode="1" android:versionname="1.0" > <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> <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.example.parse"/> </intent-filter> </receiver> <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/> </application> </manifest>
Comments
Post a Comment