一些小米和联想Android手机有一个自动启动权限,如果没有被授权,如果应用程序不在内存中,即在远离最近的应用程序部分时,应用程序不会接收GCM通知。 (这不是问题)
现在,如果我在自动启动权限设置为false的手机中启动聊天应用程序(例如whatsapp和其他人),它将开始显示之前无法提供的所有通知,因为它没有&# 39;得到许可。 (很棒)
我的问题是 - GCM负责提供这些消息,或者这些应用正在做其他事情,例如当他们发现第一次无法收到消息/通知时,会对服务器进行API调用吗?
Android清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.name">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<permission
android:name="${manifestApplicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${manifestApplicationId}.permission.C2D_MESSAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name=".ui.activities.MapActivity"
android:configChanges="orientation|screenSize"
android:exported="true"
android:parentActivityName=".ui.activities.SupportChatActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize|stateHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.activities.SupportChatActivity" />
</activity>
<activity
android:name=".ui.activities.SupportChatActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" />
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
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="${manifestApplicationId}" />
</intent-filter>
</receiver>
<service
android:name=".services.GcmBroadcastReceiverService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".services.GcmIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
</application>
</manifest>
GCMBroadcastReceiverService.java
public class GcmBroadcastReceiverService extends GcmListenerService {
private static final String TAG = "MyGcmListenerService";
private NotificationManager notificationManager;
@Override
public void onCreate() {
super.onCreate();
}
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
/*String message = data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
Log.d("GCM", "GCM recvd");
// Do whatever you want with received message
}
}
其他要点:
如果为应用启用了自动启动功能,那么一切正常。
服务器响应是 - 成功。
使用adb shell进行测试具有相同的行为。
一切都在智能手机中运行,但没有自动启动功能。
修改
这是日志显示的内容 -
a)当我使用此命令时 -
adb shell am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename.debug / .GcmBroadcastReceiver --es&#34; data.alert&#34; &#34;富&#34;
01-13 11:58:35.126 ? W/ADB_SERVICES: create_local_service_socket() name=shell:am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename.debug/.GcmBroadcastReceiver --es data.alert foo
01-13 11:58:35.126 ? W/ADB_SERVICES: service_to_fd() name=shell:am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename.debug/.GcmBroadcastReceiver --es data.alert foo
01-13 11:58:35.127 ? W/ADB_SERVICES: LS(17153): bound to 'shell:am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename.debug/.GcmBroadcastReceiver --es data.alert foo' via 17
01-13 11:58:35.751 ? V/ActivityManager: Broadcast: Intent { act=com.google.android.c2dm.intent.REGISTRATION flg=0x10 cmp=com.packagename.debug/.GcmBroadcastReceiver (has extras) } ordered=true userid=-2 callerApp=null
b)当我使用此命令时 -
adb shell am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename / .GcmBroadcastReceiver --es&#34; registration_id&#34; &#34; APA91bHk3fns3556etW8JYr0KUxJ_7GJTInDNQW23TyqKlN2nEGWcaYPC3dP6a8KmCB0VvXyfrT5jUzykzaYbvXbcYwWgcsfvsq-Q-26sBDY-Vvo1MfUkLOVf-UbsKhIWn8dU580FlzCJFvIXH9DYbit8j-OIQQ7bw&#34;
01-13 12:11:32.007 ? W/ADB_SERVICES: create_local_service_socket() name=shell:am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename/.GcmBroadcastReceiver --es registration_id APA91bHk3fns3556etW8JYr0KUxJ_7GJTInDNQW23TyqKlN2nEGWcaYPC3dP6a8KmCB0VvXyfrT5jUzykzaYbvXbcYwWgcsfvsq-Q-26sBDY-Vvo1MfUkLOVf-UbsKhIWn8dU580FlzCJFvIXH9DYbit8j-OIQQ7bw
01-13 12:11:32.007 ? W/ADB_SERVICES: service_to_fd() name=shell:am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename/.GcmBroadcastReceiver --es registration_id APA91bHk3fns3556etW8JYr0KUxJ_7GJTInDNQW23TyqKlN2nEGWcaYPC3dP6a8KmCB0VvXyfrT5jUzykzaYbvXbcYwWgcsfvsq-Q-26sBDY-Vvo1MfUkLOVf-UbsKhIWn8dU580FlzCJFvIXH9DYbit8j-OIQQ7bw
01-13 12:11:32.008 ? W/ADB_SERVICES: LS(17877): bound to 'shell:am broadcast -a com.google.android.c2dm.intent.REGISTRATION -n com.packagename/.GcmBroadcastReceiver --es registration_id APA91bHk3fns3556etW8JYr0KUxJ_7GJTInDNQW23TyqKlN2nEGWcaYPC3dP6a8KmCB0VvXyfrT5jUzykzaYbvXbcYwWgcsfvsq-Q-26sBDY-Vvo1MfUkLOVf-UbsKhIWn8dU580FlzCJFvIXH9DYbit8j-OIQQ7bw' via 17
01-13 12:11:32.560 ? V/ActivityManager: Broadcast: Intent { act=com.google.android.c2dm.intent.REGISTRATION flg=0x10 cmp=com.packagename/.GcmBroadcastReceiver (has extras) } ordered=true userid=-2 callerApp=null
c)当我使用其他app / web发送消息时:
01-13 12:13:08.979 ? D/PowerManagerService: acquireWakeLockInternal: lock=157179083, flags=0x1, tag="GCM_CONN", ws=WorkSource{10010 com.google.android.gms}, uid=10010, pid=5818
01-13 12:13:08.980 ? D/PowerManagerNotifier: onWakeLockAcquired: flags=1, tag="GCM_CONN", packageName=com.google.android.gms, ownerUid=10010, ownerPid=5818, workSource=WorkSource{10010 com.google.android.gms}
01-13 12:13:08.999 ? I/GCM: GCM message com.packagename.debug 0:1452667389212251%8d85449af9fd7ecd
01-13 12:13:09.035 ? D/PowerManagerService: releaseWakeLockInternal: lock=157179083 [GCM_CONN], flags=0x0, total_time=56ms
01-13 12:13:09.035 ? D/PowerManagerNotifier: onWakeLockReleased: flags=1, tag="GCM_CONN", packageName=com.google.android.gms, ownerUid=10010, ownerPid=5818, workSource=WorkSource{10010 com.google.android.gms}
01-13 12:13:09.028 ? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.packagename.debug (has extras) }