的通知我已经研究了小时和小时,发现了很多类似的问题,但对于我的问题没有工作解决方案。完全关闭应用程序后,无法收到来自gcm
我很明白,如果我强制关闭应用程序关闭,这是正常的,我没有收到来自gcm的数据。但我无法收到与gcm的通知,直到我启动应用程序。因此,应用程序运行的前景或背景,然后我只能够从gcm接收数据,但当我关闭应用程序通过滑动它(这不是通过强制关闭),通知没有显示gcm wasn根本没有收到任何数据。 。所以这意味着我需要保持活跃,但如果我这样做,那么使用gcm不再需要推送通知的设计。
这里是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.khooteckwei.google" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.gcmtesting.google.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcmtesting.google.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcmtesting.google" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
</application>
</manifest>
这里是wakefulBroadcastReceiver
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
通知工作正常时,应用程序是活动的,所以我不包括用来显示notification.Is功能这2页有什么问题吗?
也许你的设备在“滑走它”时执行强制停止。这不是正常的行为,但至少有一些设备制造商搞砸了,并做到了这一点。尝试运行您的应用程序,“滑开它”,然后在设置>应用程序中查看应用程序的页面。如果“强制停止”按钮被禁用,那么您知道“滑走它”会执行强制停止。 – CommonsWare
Thx回复。但该按钮已启用,所以我不认为这是问题 – user3651999
只是为了澄清,你的意思是说,如果你的应用程序在*前台*,你只能够接收gcm通知? –