【问题标题】:Notification: pass data通知:传递数据
【发布时间】:2013-07-31 08:55:47
【问题描述】:

我正在尝试将数据从通知传递到活动:

btnShedule.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            Intent notificationIntent = new Intent(Oconf.this, Oconf.class);
            notificationIntent.putExtra("test", 122);

            PendingIntent contentIntent = PendingIntent.getActivity(Oconf.this, 0, notificationIntent, 0);

            Notification notification = new Notification(R.drawable.notify_deal, "text", System.currentTimeMillis());
            notification.setLatestEventInfo(Oconf.this, getString(R.string.notify_events), "text", contentIntent);

            notification.defaults |= Notification.DEFAULT_SOUND;
            notification.flags |= Notification.FLAG_AUTO_CANCEL;

            notificationManager.notify(0, notification);
        }
    });

然后,onResume:

public void onResume() {

    String q = getIntent().getStringExtra("test");
    if (q == null) {
        Log.e(TAG, "null!");
    }
    else {
        Log.e(TAG, q);
    }

    super.onResume();
}

我得到“null!”。哪里出错了?

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    在我的情况下,当我点击通知时,从未调用过 onNewIntent()。但是我在onCreate() 方法中添加了以下代码:

    String m = getIntent().getStringExtra("put_extra_string");
    

    我得到了我试图传递给通知意图的字符串。

    【讨论】:

      【解决方案2】:

      :)

      protected void onNewIntent(Intent intent)
      
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 2015-11-30
      • 1970-01-01
      相关资源
      最近更新 更多