2016-11-05 85 views
0

我无法接收运行android以下棒棒糖的设备上的GCM消息。 Push信息适用于Android 5,6和7 我真的不知道为什么......有我的应用程序代码:无法接收消息gcm android下面的棒棒糖

清单:

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="25"/> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

<permission android:name="sbntt.android.xenoss.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" /> 
<uses-permission android:name="sbntt.android.xenoss.permission.C2D_MESSAGE" /> 

<application 
    android:name="android.support.multidex.MultiDexApplication" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

    <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="sbntt.android.xenoss" /> 
     </intent-filter> 
    </receiver> 
    <service 
     android:name="sbntt.android.xenoss.GCMPushReceiverService" 
     android:exported="false" > 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
     </intent-filter> 
    </service> 
    <service 
     android:name=".GCMRegistrationIntentService" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="com.google.android.gms.iid.InstanceID" /> 
     </intent-filter> 
    </service> 
    <service 
     android:name=".GCMTokenRefreshListenerService" 
     android:exported="false"> 
    </service> 

</application> 

GCMPushReceiverService类

@Override 
public void onMessageReceived(String from, Bundle data) { 
    String message = data.getString("message"); 
    if (Settings.preference != null) { 
     if (Settings.preference.getBoolean("notifications", true)) { 
      sendNotification(message); 
     } 
    } else { 
     sendNotification(message); 
    } 
} 


private void sendNotification(String message) { 
    Intent intent = new Intent(this, MainActivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    int requestCode = 0; 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT); 
    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.drawable.ic_menu_youtube) 
      .setContentTitle("TITLE") 
      .setContentText(message) 
      .setAutoCancel(true) 
      .setContentIntent(pendingIntent) 
      .setSound(sound) 
      .setDefaults(Notification.DEFAULT_ALL) 
      .setPriority(Notification.PRIORITY_HIGH); 

    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(0, noBuilder.build()); 
} 

注册工作正常! 感谢您的帮助。

回答

0

GCM需要更新在设备上播放服务。您可以通知用户更新Play服务或在您的项目中使用较少的播放服务版本。

+0

主要活动有玩服务检查。运行kitkat的设备有最新的谷歌播放服务版本 – SBNTT

+0

您在adb中收到任何消息日志机智播放服务标签? –

+0

我卸载了播放服务更新decives,然后我再次更新它,它的工作原理...感谢您的帮助 – SBNTT