如何通过Notification将字符串数组从BroadcastReceiver传递到Activity类

发布于 2024-12-01 20:07:57 字数 1532 浏览 1 评论 0原文

我想将一个字符串从广播接收器传递到活动。当我点击通知时,我已发出通知。我正在该活动中启动一个活动,我想显示字符串数组值:

我已经编写了一个 BroadcastReceiver 类,如下所示:

public class RepeatingAlarm extends BroadcastReceiver
   {
       @Override
     public void onReceive(Context context, Intent intent)
      {
        String array[5]={"hai","hello","how r u?","welcome"};

        //i am calling notification method here
       notification();

       }

   }

我已经编写了一个用于获取通知的方法,如下所示

public static void myNotify(Context context,String message)
 {

      NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
      Notification notification = new Notification(R.drawable.icon,"A new notification", System.currentTimeMillis());
      // Hide the notification after its selected
      notification.flags |= Notification.FLAG_AUTO_CANCEL;

      //Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(""));

      Intent notificationIntent = new Intent(context.getApplicationContext(), CustomDialogExample.class);// i am starting CustomDialogExample 

      PendingIntent activity = PendingIntent.getActivity(context,0,notificationIntent, 0);

      notification.setLatestEventInfo(context,"Notification for you",message,activity);

      notification.number += 1;

      notificationManager.notify(0, notification);

 } 

从上面的方法我正在启动 CustomDialogExample 活动。当我单击“通知”时,我希望获得 RepeatingAlarm 类 arra[] 将在 CustomDialogExample 类中获得。

请任何人帮助我

I would like to pass a string from broadcast receiver to activity. I have raised a notification when I clicked on notification. I am starting an activity in that activity I would like to show string array values:

I have write a class of BroadcastReceiver as shown below:

public class RepeatingAlarm extends BroadcastReceiver
   {
       @Override
     public void onReceive(Context context, Intent intent)
      {
        String array[5]={"hai","hello","how r u?","welcome"};

        //i am calling notification method here
       notification();

       }

   }

I have write a method for get the notification as shown below

public static void myNotify(Context context,String message)
 {

      NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
      Notification notification = new Notification(R.drawable.icon,"A new notification", System.currentTimeMillis());
      // Hide the notification after its selected
      notification.flags |= Notification.FLAG_AUTO_CANCEL;

      //Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(""));

      Intent notificationIntent = new Intent(context.getApplicationContext(), CustomDialogExample.class);// i am starting CustomDialogExample 

      PendingIntent activity = PendingIntent.getActivity(context,0,notificationIntent, 0);

      notification.setLatestEventInfo(context,"Notification for you",message,activity);

      notification.number += 1;

      notificationManager.notify(0, notification);

 } 

From the above method I am starting CustomDialogExample activity. When I clicked on Notification I would like to get the RepeatingAlarm class arra[] will get in CustomDialogExample class.

please any body help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪推晚风 2024-12-08 20:07:57

您应该使用 Intent.putStringArrayListExtra() 函数。这是示例:

 ArrayList<String> strings = new ArrayList<String>();
 strings.add("item1");
 ...
 strings.add("itemN");
 notificationIntent.putStringArrayListExtra("stringArrayArg", strings);

You should use Intent.putStringArrayListExtra() function for this. Here is example:

 ArrayList<String> strings = new ArrayList<String>();
 strings.add("item1");
 ...
 strings.add("itemN");
 notificationIntent.putStringArrayListExtra("stringArrayArg", strings);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文