【问题标题】:I can not get the parameters from notification intent我无法从通知意图中获取参数
【发布时间】:2014-12-12 05:44:57
【问题描述】:

我正在尝试通过通知传递参数

private void generateNotification(Context context, String title, String message,int groupid,int count) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        Intent intent = new Intent(context,MyActivity.class);
        intent.putExtra("group_id",groupid);
        Log.d("mylogout","group_id: "+groupid);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        Notification notification   = new NotificationCompat.Builder(context)
                .setContentIntent(pendingIntent)
               .................
                .build();
        notification.number=count;
        notificationManager.notify(groupid, notification);
    }

并在我的活动中使用它

Log.d("mylogout","id from: "+getIntent().getStringExtra("group_id"));

但由于某种原因,第一个日志写入 id = 3 但在 MyActivity 日志中写入D/mylogout﹕ id feom main: null

【问题讨论】:

  • groupid 是 int 或 string

标签: android android-intent android-notifications


【解决方案1】:

试试这个。

getIntent().getIntExtra("group_id", 0);

您将 groupid 作为方法参数中的“整数”。

private void generateNotification(Context context, String title, String message,int groupid,int count)

但尝试在活动中将其作为字符串获取将返回 null。

【讨论】:

  • 我的错误。谢谢。我以为是字符串ID,忘记改类型了。
猜你喜欢
  • 1970-01-01
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多