Problems setting Push Notifications on Android with Parse -
i've been trying receive push notifications in android , had problems. me?
1) basic implementation works fine in android 4.0+, not in android 2.3, why?
2) i've implemented custom receiver tutorial explains, had inserted lines on androidmanifest
tutorial showed (maintaining <service android:name="com.parse.pushservice" />
) , i've removed line define defaultpushcallback
, right? when send push dashboard, app receives , show default message, not passing in custom receiver, parse informations have sent.
use given manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your package name" android:versioncode="3" android:versionname="1.1" > <uses-sdk android:minsdkversion="4" android:targetsdkversion="13" /> <uses-permission android:name="android.permission.internet" /> <!-- gcm requires google account. --> <uses-permission android:name="android.permission.get_accounts" /> <!-- keeps processor sleeping when message received. --> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.read_phone_state" /> <uses-permission android:name="android.permission.receive_boot_completed" /> <uses-permission android:name="android.permission.quickboot_poweron" /> <uses-permission android:name="android.permission.vibrate" /> <application android:name="com.test.param.mainactivity" android:allowbackup="true" android:icon="@drawable/menu" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="splash" android:label="@string/app_name" android:theme="@android:style/theme.notitlebar" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.test.param..profile" android:screenorientation="portrait" android:windowsoftinputmode="adjustpan" > </activity> <activity android:name="com.test.param.announceactivity" android:screenorientation="portrait" android:label="@string/app_name" > </activity> <activity android:name="com.test.param.menuactivity" android:screenorientation="portrait" > </activity> > </activity> <activity android:name="com.test.param.showpopup" android:screenorientation="portrait" android:label="@string/app_name" android:theme="@android:style/theme.holo.light.dialog" > </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.receive_boot_completed" /> <action android:name="android.intent.action.quickboot_poweron" /> <action android:name="android.intent.action.user_present" /> <category android:name="android.intent.category.default" /> </intent-filter> </receiver> <receiver android:name="com.test.param.mycustomreceiver" > <intent-filter> <action android:name="android.intent.action.boot_completed" /> <action android:name="android.intent.action.user_present" /> <action android:name="android.intent.action.receive_boot_completed" /> <action android:name="android.intent.action.quickboot_poweron" /> <action android:name="com.test.param.update_status" /> <category android:name="android.intent.category.default" /> </intent-filter> </receiver> </application> </manifest> ---------- use send push notification jsonobject obj; try { obj = new jsonobject(); obj.put("alert", "hello"); obj.put("action", "*your main package name*.update_status"); obj.put("title", "param"); obj.put("msg", "today meeting @ 9 "); obj.put("time", currentdate.getcurrentdate()); parsepush push = new parsepush(); @suppresswarnings("rawtypes") parsequery query = parseinstallation.getquery(); // notification android users query.whereequalto("devicetype", "android"); push.setquery(query); push.setdata(obj); push.sendinbackground(); } catch (jsonexception e) { e.printstacktrace(); } use custom receiver class..... public class mycustomreceiver extends broadcastreceiver { string title, time,msg; @override public void onreceive(context context, intent intent) { bundle extras = intent.getextras(); string message = extras != null ? extras.getstring("com.parse.data") : ""; log.e("message ", " " + message); jsonobject jobject; try { if (message != null && !message.equals("")) { jobject = new jsonobject(message); time = jobject.getstring("time"); msg = jobject.getstring("title"); title = jobject.getstring("msg"); } } catch (jsonexception e) { e.printstacktrace(); } } } ---------- , dont remove defaultpushcallback have implemented , it's working fine
Comments
Post a Comment