2014-02-22 1 views
0

내 앱에서 gcm.jar을 통해 앱에 통합 푸시 알림이 작동했는데 8 시간 전까지 정상적으로 작동했습니다. 나는 마지막 한 통을받은 때가되었다는 것을 안다. 매니페스트 푸시 알림 Android가 정상적으로 작동 중이며 갑자기 중지됨

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/

여기 내 GCM 의도 서비스입니다 지금은 내가 밀고있는 알림을받지 못하고 있습니다. 내가 확인한 : http://developer.android.com/google/gcm/index.html

새로운 GCM을 강제로 구현해야만 작동합니까, 아니면 내 의도 서비스에 문제가 있습니까?

답변

0

오래된 앱 중 하나에서 C2DM을 사용하고 푸시 테스트를했는데 여기에서 작동합니다. 가끔은 와이파이 가정 라우터 또는 어떤 rauter 뒤에 푸시가 통과되지 않습니다, 아마 그것은 단지 내 라우터지만, 어쨌든 라우터를 다시 시작합니다. 마이그레이션하는 것은 나쁜 생각이 아니며, 일주일이 걸렸습니다. migrate page

+0

감사합니다. 마이그레이션하는 방법은 무엇입니까? Google에서 제외하고 다른 유용한 링크가 있습니까 (질문에서 언급 했음). 아직 작동하지 않아야하는 이유가 무엇입니까? –

+0

C2DM을 알고 있기 때문에 GCM 튜토리얼을 골라 처음부터 튜토리얼 프로젝트에서 시작할 수 있습니다. 그냥 구글. 그것이 나를 위해 일하고 있기 때문에 그것은 당신을 위해 일해야합니다. 어쩌면 은행 계좌가 서버에 전송되지 않았을 수도 있습니다 – Erik

+0

시작하려면 [migrate page] (http://developer.android.com/google/gcm/c2dm.html) – Erik