未在 android 中使用 parse.com 获取推送通知
Posted
技术标签:
【中文标题】未在 android 中使用 parse.com 获取推送通知【英文标题】:Not Getting Push noitification using parse.com in android 【发布时间】:2014-07-31 07:44:47 【问题描述】:我做了一个android演示,我已经实现了解析推送通知,我按照告诉的步骤进行了操作,但是我没有在设备上收到任何通知,请帮助我这段代码有什么问题,我的代码如下: application.java
Parse.initialize(this, "My app_id",
"Client_key");
PushService.setDefaultPushCallback(this, QuestionOFDayActivity.class);
// PushService.unsubscribe(getApplicationContext(), "MQOD");
PushService.subscribe(getApplicationContext(), "MQOD",
QuestionOFDayActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush push = new ParsePush();
String message = "Client message";
push.setChannel("Channel Name");
push.setMessage(message);
push.sendInBackground();
manifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission
android:name="com.medicineqod.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.medicineqod.permission.C2D_MESSAGE" />
<application
android:name="com.medicineqod.Application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyApp.Theme.Light.NoTitleBar" >
<meta-data
android:name="droidparts_dependency_provider"
android:value=".DependencyProvider" />
<activity
android:name="com.medicineqod.activity.SplashScreenActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.medicineqod.activity.HomeActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.medicineqod.activity.QuestionOFDayActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.medicineqod.activity.FavouriteQuestionActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.medicineqod.activity.PastQuestionActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.medicineqod.activity.MyPerformanceActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<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.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" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
<category android:name="com.medicineqod" />
</intent-filter>
</receiver>
</application>
【问题讨论】:
【参考方案1】:但必须启用客户端推送? 如果没有转到您的解析仪表板并转到设置并单击推送通知,您将看到 CLIENT PUSH ENABLED?关闭,打开它,你会完成.. 那么我想一个:既然这是解析,你应该删除除解析之外的所有接收器,解析 将在没有 gcm 接收器的帮助下自动发送它。应该是这样的
<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>
它是否还在仪表板上显示已发送? 二:您的情况下的setchannel输入应该收到“MQOD”,您可以向自己发送推送.. 试试看..让我知道
【讨论】:
是的,谢谢,我已启用它,实际上我很困惑,因为当我从 parse.com“手动”发送通知时我收到通知非常好,但我希望它自动发送(不是点击从解析网站发送按钮)。有我的疑问吗?以上是关于未在 android 中使用 parse.com 获取推送通知的主要内容,如果未能解决你的问题,请参考以下文章
Android:如何使用 Parse.com 的 Bolts 同步查询?
如何使用 parse.com 将 Android 设备注册到推送通道