2011-12-26 5 views
1

私はプッシュ通知を表示するアンドロイドアプリを作成しています。私は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(); 
     } 
    } 

誰もがどこ問題になる可能性が私に言うことができますか? ありがとう

答えて

0

送信側に問題がある可能性があります。サーバーからメッセージを送信すると、何が得られますか?

関連する問題