我已经编写了一个应用程序,在这个应用程序中,我可以向用户发送通知。在第一个版本中,没有问题。然后我用相同的密钥进行了修改,我开始遇到问题。
某些设备不再收到任何通知,其中一个设备是我的设备。后来,我发现我的设备和其他人不再接受来自GCM服务的任何通知,即使我将我的应用程序的新版本与GCM一起放入新密钥或任何应用程序都有GCM。
已更新到我的应用程序新版本的其他人已向我报告此问题。但是一些更新应用程序的用户可以毫无问题地使用它们。我的意思是对于一些用户,该应用程序继续正常工作。
当我运行SuperVPN应用程序时,所有通知都已发送! 所以两台设备连接到同一路由器 第一个正常收到通知 另一个没有收到没有SuperVPN的人
manifist.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.labyb.englishwordeachday"
android:versionCode="2"
android:versionName="2.0.0" >
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<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="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<permission
android:name="com.labyb.englishwordeachday.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.labyb.englishwordeachday.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.labyb.englishwordeachday.WordActivity"
android:label="@string/app_name"
android:parentActivityName=".AllWordsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.AddsActivity"
android:label="@string/title_activity_adds"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.AllWordsActivity"
android:label="@string/title_activity_list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.SplashActivity"
android:label="@string/title_activity_splash"
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.labyb.englishwordeachday.SearchActivity"
android:label="@string/title_activity_search"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.TranslateActivity"
android:label="@string/title_activity_translate"
android:theme="@android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.TestActivity"
android:label="@string/title_activity_test_new" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.ReminderActivity"
android:label="@string/title_activity_reminder"
android:theme="@android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.SetReminderActivity"
android:label="@string/title_activity_set_reminder"
android:theme="@android:style/Theme.Holo.Light.Dialog" >
</activity>
<receiver android:name="com.labyb.englishwordeachday.MyReceiver" >
<intent-filter>
<action android:name="com.labyb.englishwordeachday.mybroadcast" />
</intent-filter>
</receiver>
<activity
android:name="com.labyb.englishwordeachday.RemindersActivity"
android:label="@string/title_activity_reminders" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.SpeachActivity"
android:label="@string/title_activity_speach"
android:theme="@android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.LevelsActivity"
android:label="@string/title_activity_levels" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.WebActivity"
android:label="@string/title_activity_web" >
</activity>
<receiver
android:name="com.labyb.englishwordeachday.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" />
<category android:name="com.labyb.englishwordeachday" />
</intent-filter>
</receiver>
<service android:name="com.labyb.englishwordeachday.GcmIntentService" />
<receiver android:name=".StartUpBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
GcmBroadcastReceiver.java
package com.labyb.englishwordeachday;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
GcmIntentService.java
package com.labyb.englishwordeachday;
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.labyb.englishwordeachday.classes.Adds;
import com.labyb.englishwordeachday.classes.DatabaseHandler;
public class GcmIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
DatabaseHandler db;
static int counter = 0;
public GcmIntentService() {
super("GcmIntentService");
}
public static final String TAG = "GCM Demo";
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: "
+ extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(),
"Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(),
"Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// for (int i = 0; i < 5; i++) {
// Log.i(TAG, "Working... " + (i + 1) + "/5 @ " +
// SystemClock.elapsedRealtime());
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// }
// }
Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
sendNotification(extras.get("word_id").toString(), extras.get("m1").toString(), extras.get("m2").toString(), extras.get("m3").toString(), extras.get("m4").toString(), extras.get("m5")
.toString(), extras.get("m6").toString(), extras.get("m7").toString(), extras.get("level").toString());
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
long[] vibraPattern = { 500, 500, 500, 500 };
private void sendNotification(String word_id, String m1, String m2, String m3, String m4, String m5, String m6, String m7, String level) {
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (m4.equals("v1")) {
} else if (m1.equals("newadd")) {
Intent myIntent = new Intent(this, AddsActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle("قد يهمك ايضا")
.setStyle(new NotificationCompat.BigTextStyle().bigText(m2)).setAutoCancel(true).setTicker("قد يهمك ايضا").setVibrate(vibraPattern)
.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.ewed)).setContentText(m2);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
counter = counter + 1;
db = new DatabaseHandler(this);
db.addAdd(new Adds(m3, m2));// /hereeeeeeeeeeeeee
} else {
Intent i = new Intent(this, WordActivity.class);
i.putExtra("id", word_id);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, i, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle(m1)
.setStyle(new NotificationCompat.BigTextStyle().bigText(m1)).setAutoCancel(true).setTicker("كلمة إنجليزية جديدة").setVibrate(vibraPattern)
.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.ewed)).setContentText(m2);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
counter = counter + 1;
db = new DatabaseHandler(this);
db.addNewWord(word_id, m1, m2, m3, m4, m5, m6, m7, level);// /hereeeeeeeeeeeeee
}
}
}