0
我已經加入Android上的GCM
通知服務工作正常,但是當設備被重新啓動我沒有看到傳遞到應用程序的任何消息後,不會傳遞到應用程序。GCM消息,但手機重啓
我檢查打印的日誌和它顯示我日誌說:
"I/GCM﹕ GCM message com.package.name 0:1438085xxxxxxxxxxxxxxxxxx"
,這意味着由所述設備接收到的消息,但它不被轉發到該應用。有什麼建議麼?
這裏是我的onMessageReceived如何實施:
公共無效onMessageReceived(String一個,捆數據){
Logger.info(TAG, "GOT PUSH NOTIFICATION");
final Session session = Session.getInstance();
if(session == null){
Logger.error("Not Handling Message.\nSession does not exist.");
return;
}else{
if(session.apiKey == null){
Logger.error("Not Handling Message.\nUser is not Logged In.");
return;
}
}
/**
* IF ACTIVITY IS IN CLOSED STATE STOP PRICE TIMER
* */
if(session.activityInClosedState){
new Thread(new Runnable() {
@Override
public void run() {
Logger.info("Stopping Price Timer");
session.stopTimer();
}
}).start();
}
/** ALWAYS WORKS IN BACKGROUND THREAD*/
try{
PushNotification pushNotification = new PushNotification(data);
updateNotificationBar(pushNotification);
session.onNewAlert();
}catch (Exception ex){
Logger.error("Exception: "+ex);
}
}
這裏是清單文件:
<?xml version="1.0" encoding="utf-8"?>
<uses-feature android:glEsVersion="0x00020000" android:required="false"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.sentieo.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.sentieo.gcm.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:name=".objects.Session"
android:icon="@mipmap/appicon"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait"
android:launchMode="singleTop"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--GCM REGISTRATION STARTS -->
<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="com.sentieo.gcm" />
</intent-filter>
</receiver>
<receiver android:name=".pushnotifications.GCMListenerService$NotificationCancelledBroadCastReceiver"
android:exported="false"
>
</receiver>
<service android:name=".pushnotifications.RegistrationIntentService" android:enabled="true"></service>
<service
android:name=".pushnotifications.GCMListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".pushnotifications.InstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<!--GCM REGISTRATION ENDS -->
</application>
你是如何處理的消息?您是否實施了廣播接收器+意向服務+爲您的應用添加了權限? –
@MimmoGrottoli:是的。我做到了。當我第一次安裝我的應用程序時,它工作正常。即使我殺了我的應用程序並重新啓動它,然後我也收到消息。但是,當我重新啓動手機時,設備收到的任何消息都不會傳送到應用程序。 –
廣播是否在清單內部註冊?共享清單文件 –