推送通知安卓工作正常以前,突然停止


通过

gcm在应用程序中集成了推送通知.jar在我的应用程序中,直到8小时前才能正常工作。我知道,因为那是我收到最后一个的时间。

这是我的GCM意图服务:

public class GCMIntentService extends GCMBaseIntentService {
    private static final String TAG = "GCMIntentService";
    public GCMIntentService() {
        super(CommonUtilities.SENDER_ID);
    }
    @Override
    protected void onRegistered(Context context, String registrationId) {
        Log.i(TAG, "Device registered: regId = " + registrationId);
        CommonUtilities.displayMessage(context, getString(R.string.gcm_registered));
        ServerUtilities.register(context, registrationId);
    }
    @Override
    protected void onUnregistered(Context context, String registrationId) {
        Log.i(TAG, "Device unregistered");
        CommonUtilities.displayMessage(context, getString(R.string.gcm_unregistered));
        if (GCMRegistrar.isRegisteredOnServer(context)) {
            ServerUtilities.unregister(context, registrationId);
        } else {
            // This callback results from the call to unregister made on
            // ServerUtilities when the registration to the server failed.
            Log.i(TAG, "Ignoring unregister callback");
        }
    }
    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
        String message = intent.getStringExtra("message");
        String url = intent.getStringExtra("url");
        CommonUtilities.displayMessage(context, message);
        // notifies user
        generateNotification(context, message, url);
    }
    @Override
    protected void onDeletedMessages(Context context, int total) {
        Log.i(TAG, "Received deleted messages notification");
        String message = getString(R.string.gcm_deleted, total);
        CommonUtilities.displayMessage(context, message);
        // notifies user
        generateNotification(context, message,"");
    }
    @Override
    public void onError(Context context, String errorId) {
        Log.i(TAG, "Received error: " + errorId);
        CommonUtilities.displayMessage(context, getString(R.string.gcm_error, errorId));
    }
    @Override
    protected boolean onRecoverableError(Context context, String errorId) {
        // log message
        Log.i(TAG, "Received recoverable error: " + errorId);
        CommonUtilities.displayMessage(context, getString(R.string.gcm_recoverable_error,
                errorId));
        return super.onRecoverableError(context, errorId);
    }
    /**
     * Issues a notification to inform the user that server has sent a message.
     */
    private static void generateNotification(Context context, String message, String url) {
        int icon = R.drawable.app_icon;
        long when = System.currentTimeMillis();
        Log.e(TAG, message);
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
        String title = context.getString(R.string.app_name);
        Intent notificationIntent;
        if(!TextUtils.isEmpty(url)){
            notificationIntent= new Intent(Intent.ACTION_VIEW);
            notificationIntent.setData(Uri.parse(url));
        }else{
            notificationIntent= new Intent(context, SplashScreen.class);
            notificationIntent.putExtra("message", message);
        }
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    }
}  

并具有适当的权限,在清单中:

    <receiver
        android:name="com.google.android.gcm.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.packageappname" />
        </intent-filter>
    </receiver>

已经提到(实际上正是这样实现的):http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

现在我没有收到正在推送的通知。我检查了:http://developer.android.com/google/gcm/index.html

我是否必须强制实施新的 GCM 才能使其正常工作,或者我的意向服务是否存在问题?

我在我的一个旧应用程序中使用 C2DM,并且刚刚测试了推送,它在这里工作。有时在wifi家用路由器或任何推机后面没有通过,也许这只是我的路由器,但无论如何重新启动路由器。迁移并不是一个坏主意,我做到了,花了我一周的时间来学习和正确处理。您是否看到迁移页面

最新更新