android:通知没有做任何事情

时间:2014-12-05 11:04:43

标签: java android android-intent notifications google-cloud-messaging

嘿所有我正在创建一个用户可以向对方发送gcm消息的应用程序 应用程序工作得非常好,当我发送gcm消息时,接收方将其作为通知 当接收器点击它时打开homepage.class但问题是 当他点击通知时,广播接收器没有接收到它并且没有对EditText进行更改,另一方面,如果接收者在收到消息时使用了homepage.class,则进行更改&# 39; s到EditText(工作) 可能是什么问题呢 ??? 我的GCMIntentService

中的一些方法
 @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);   
    } 

这是我的BroadcastReceiver的代码

@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);                  
    }
};

如果有人知道答案告诉我(抱歉英语不好)

1 个答案:

答案 0 :(得分:0)

确保在其父活动上注册接收器。一旦正确注册,它就会处理收到的捆绑包。注意发送的值标签。