我遵循不同的教程,我正在尝试从他们的网络平台发送通知,但似乎没有任何效果.这是我迄今为止所尝试的.
这是我的Application类的onCreate方法
@H_502_5@@OverrIDe public voID onCreate() { super.onCreate(); Log.i("PushNotifications","PARSE initialize"); Parse.initialize(this,"******************************","*****************************"); ParseInstallation.getCurrentInstallation().saveInBackground(); ParsePush.subscribeInBackground("",new SaveCallback() { @OverrIDe public voID done(ParseException e) { if (e == null) { Log.i("PushNotifications","com.parse.push" + " successfully subscribed to the broadcast channel."); } else { Log.i("PushNotifications","com.parse.push" + " Failed to subscribe for push"); } } }); }这被称为成功,因为我得到日志
successfully subscribed to the broadcast channel.
这里还有我的清单文件的一些相关内容:
@H_502_5@<uses-permission androID:name="androID.permission.INTERNET"/><uses-permission androID:name="com.Google.androID.provIDers.gsf.permission.READ_GSERVICES" /><permission androID:name="com.my.app.permission.C2D_MESSAGE" androID:protectionLevel="signature" /><uses-permission androID:name="com.my.app.permission.C2D_MESSAGE" /><uses-permission androID:name="com.Google.androID.c2dm.permission.RECEIVE" /><uses-permission androID:name="androID.permission.VIBRATE" /><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.GET_ACCOUNTS" /><uses-permission androID:name="androID.permission.WRITE_INTERNAL_STORAGE" /><uses-permission androID:name="androID.permission.WRITE_INTERNAL_STORAGE" /><uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission androID:name="androID.permission.READ_EXTERNAL_STORAGE" /><uses-permission androID:name="androID.permission.READ_PHONE_STATE" /><uses-permission androID:name="androID.permission.READ_CONTACTS"/><uses-permission androID:name="androID.permission.SEND_SMS" /><uses-permission androID:name="androID.permission.CAMERA" /><uses-feature androID:name="androID.harDWare.camera" /><application androID:allowBackup="true" androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" androID:name=".App" androID:theme="@style/Apptheme"> <activity androID:name=".activitIEs.MainActivity" androID:launchMode="standard" androID:screenorIEntation="sensorPortrait"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <Meta-data androID:name="com.parse.push.gcm_sender_ID" androID:value="ID:123456789" /> <Meta-data androID:name="com.parse.push.notification_icon" androID:resource="@drawable/ic_launcher"/> <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.parse.ParsePushbroadcastReceiver" 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> <!--com.parse.GcmbroadcastReceiver"--> <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.my.app" /> </intent-filter> </receiver></application>当我尝试从Parse网站发送推送,没有任何反应.
由于这不起作用,我尝试实现我自己的GcmbroadcastReceiver并在清单中更改它.
@H_502_5@<receiver androID:name=".receivers.MyCustomreceiver" 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.my.app" /> </intent-filter></receiver>和
@H_502_5@public class MyCustomreceiver extends broadcastReceiver { @OverrIDe public voID onReceive(Context context,Intent intent) { Log.i("PushNotifications","MyCustomreceiver"); }}没有成功.
然后我也尝试创建我自己的ParsePushbroadcastReceiver(通过从ParsePushbroadcastReceiver继承).
@H_502_5@<receiver androID:name=".receivers.CustomParseReceiver" 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>和
@H_502_5@public class CustomParseReceiver extends ParsePushbroadcastReceiver { @OverrIDe protected Notification getNotification(Context context,"PARSE getNotification"); return null; } @OverrIDe protected voID onPushOpen(Context context,"PARSE onPushOpen"); } @OverrIDe protected voID onPushReceive(Context context,"PARSE onPushReceive"); } private JsONObject getDataFromIntent(Intent intent) { Log.i("PushNotifications","PARSE getDataFromIntent"); }}它也没有工作.
事情是..当我创建自己的GCM broadcastReceiver并且我从我自己的服务器发送通知(有一些小的PHP脚本),通知被成功接收.
我真的很想知道我实施客户端解析通知系统有什么问题.
任何暗示问题可能来自哪里?
解决方法 我的2美分(希望这有帮助):我有一个类似的问题,我解决了(解释为Here),所以这可能是问题,如果没有,看看我的文件,匆匆一瞥,他们似乎有一些小的差异,他们的工作,所以它是值得一看:
清单部分:
@H_502_5@<!-- for parse pushes --> <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.MyStuff.stuff.utils.MyPushReceiver" androID:exported="false" > <intent-filter> <action androID:name="com.parse.push.intent.RECEIVE" /> <action androID:name="com.parse.push.intent.OPEN" /> <action androID:name="com.parse.push.intent.DELETE" /> </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.MyStuff.stuff" /> </intent-filter> </receiver> <Meta-data androID:name="com.parse.push.notification_icon" androID:resource="@drawable/ic_launcher" />我实现了我自己的ParsePushbroadcastReceiver:
@H_502_5@public class MyPushReceiver extends ParsePushbroadcastReceiver{ @OverrIDe protected voID onPushOpen(Context context,Intent intent) { //bla bla... } @OverrIDe protected voID onPushReceive(Context context,Intent intent) { // bla bla... } @OverrIDe protected Notification getNotification(Context context,Intent intent) { Notification notification = super.getNotification(context,intent); // do some stuff with it.. }}和我的应用程序类:
@H_502_5@public class MyApplication extends Application{ private static final String CKey = "***********"; private static final String AID = "************"; @OverrIDe public voID onCreate() { super.onCreate(); Parse.initialize(this,AID,CKey); //initialized some stuff.. ParsePush.subscribeInBackground("",new SaveCallback() { @OverrIDe public voID done(ParseException e) { if (null == e) { ParseInstallation install = ParseInstallation.getCurrentInstallation(); String token = install.getString("devicetoken"); //do some stuff with it... } } }); ParseInstallation.getCurrentInstallation().saveInBackground(); //some more stuff }希望它让你走上正确的道路!
总结以上是内存溢出为你收集整理的解析Android上的通知将无法正常工作全部内容,希望文章能够帮你解决解析Android上的通知将无法正常工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)