0

嘿所有我正在做一個應用程序,用戶可以發送gcm消息給對方 該應用程序運行非常好,當我發送gcm消息時,接收方將它作爲通知 和當接收者點擊它打開homepage.class,但問題是,當他點擊通知廣播接收器沒有收到它,並且沒有改變EditText時, ,另一方面,如果接收器是使用homepage.class收到消息時,它會改變EditText(Working) 有什麼問題? 一些從我GCMIntentServiceandroid:通知不會做任何事

@Override 
    private static void generateNotification(Context context, String message) { 
     int icon = R.drawable.ic_launcher; 
     long when = System.currentTimeMillis(); 
     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 = new Intent(context, HomePage.class); 
     // 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; 
     // Play default notification sound 
     notification.defaults |= Notification.DEFAULT_SOUND; 

     // Vibrate if vibrate is enabled 
     notification.defaults |= Notification.DEFAULT_VIBRATE; 
     notificationManager.notify(0, notification); 
    } 


    @Override 
    protected void onMessage(Context context, Intent intent) { 

     String message = intent.getExtras().getString("message"); 
     // notifies user 
     aController.displayMessageOnScreen(context, message); 
     generateNotification(context, message); 

    } 

void displayMessageOnScreen(Context context, String message) { 

     Intent intent = new Intent("com.ms.gp.wefamily.DISPLAY_MESSAGE"); 
     intent.putExtra("message", message); 
     // Send Broadcast to Broadcast receiver with message 
     context.sendBroadcast(intent); 
    } 

方法,這是我的廣播接收器的代碼

@Override 
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() { 

    public void onReceive(Context context, Intent intent) { 
     String newMessage = intent.getExtras().getString("message"); 
     // Display message on the screen 
     Familyname.setText(newMessage);     
    } 
}; 

請,如果有人知道答案告訴我,(對不起,我英文不好)

+0

這個問題對我來說還不清楚,爲什麼要通過點擊通知來觸發broadcastreceiver? – 2014-12-05 11:14:03

+0

另外,你有一個叫做Familiyname的類?或者它應該是一個字段... – 2014-12-05 11:16:06

+0

Familyname是一個EditText對象 ,如果broadcastreceiver沒有觸發通知 應該是什麼? – 2014-12-05 13:11:25

回答

0

確保您註冊接收者在其父母活動中。一旦它正確註冊,它就會處理收到的包。注意發送的價值標籤。