내 앱에서 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을 강제로 구현해야만 작동합니까, 아니면 내 의도 서비스에 문제가 있습니까?
감사합니다. 마이그레이션하는 방법은 무엇입니까? Google에서 제외하고 다른 유용한 링크가 있습니까 (질문에서 언급 했음). 아직 작동하지 않아야하는 이유가 무엇입니까? –
C2DM을 알고 있기 때문에 GCM 튜토리얼을 골라 처음부터 튜토리얼 프로젝트에서 시작할 수 있습니다. 그냥 구글. 그것이 나를 위해 일하고 있기 때문에 그것은 당신을 위해 일해야합니다. 어쩌면 은행 계좌가 서버에 전송되지 않았을 수도 있습니다 – Erik
시작하려면 [migrate page] (http://developer.android.com/google/gcm/c2dm.html) – Erik