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

确保您注册接收者在其父母活动中。一旦它正确注册,它就会处理收到的包。注意发送的价值标签。

相关问题