1
푸시 알림을 표시하려는 Android 앱을 만들고 있습니다. 나는 c2dm의 코드를 구현했다.c2dm 알림을받지 못했습니다.
하지만 등록 ID 만 제공하고 알림은 표시하지 않습니다. 활동에
: 나는 그것을 위해 코드를 다음 사용하고
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender", "[email protected]");
registrationIntent.setPackage("com.google.android.gsf");
startService(registrationIntent);
그리고 리시버에
: public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
System.out.println("action is " + action);
Log.w("C2DM", "Registration Receiver called");
if ("com.google.android.c2dm.intent.REGISTRATION".equals(action))
{
Log.w("C2DM", "Received registration ID");
registrationId = intent.getStringExtra("registration_id");
String error = intent.getStringExtra("error");
Log.d("C2DM", "dmControl: registrationId = " + registrationId + ", error = " + error);
String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
sendRegistrationIdToServer(deviceId, registrationId);
}
else if ("com.google.android.c2dm.intent.RECEIVE".equals(action))
{
handleMessage(context, intent);
createNotification(context, registrationId);
}
}
public void createNotification(Context context, String registrationId)
{
URL url;
try
{
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification =
new Notification(R.drawable.icon, "Registration successful",
System.currentTimeMillis());
String notificationTitle = "notification";
String notificationText = "New Notification from Bingo Diary";
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context, BingoDiaryActivity.class);
intent.putExtra("registration_id", registrationId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
//notification.setLatestEventInfo(context, "Registration",
// "Successfully registered", pendingIntent);
notificationManager.notify(99, notification);
notification.setLatestEventInfo(context, notificationTitle, notificationText, pendingIntent);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
사람이 어디있을 수있는 문제를 말해 줄 수? 감사합니다.