状态栏通知的单击事件

时间:2012-12-14 19:27:52

标签: android

我有一个通知栏(每天2个事件)。一个字符串数组的小列表,一个获取随机数的方法和下面的代码。

我需要点击事件并在该活动上打开一个带有字符串变量show的新活动(not1 [x])。

怎么办?

随机();

String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
        int icon = R.drawable.ic_launcher2;
        CharSequence tickerText = not1[x];
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
        CharSequence contentTitle = "Title";
        CharSequence contentText = not1[x];;
        Intent notificationIntent = new Intent();
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        final int HELLO_ID = 1;
        mNotificationManager.notify(HELLO_ID, notification);

1 个答案:

答案 0 :(得分:1)

只需更改您的代码

Intent notificationIntent = new Intent(context,yourActivityclass);
   PendingIntent contentIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0);

只需使用String

的代码
Intent i = new Intent();
i.putExtra("key", stringValue);

Intent other = new Intent()
other.getStringExtra(key)