【问题标题】:How to get requestCode from pending intent at the time of alarm in android如何在android报警时从待处理的意图中获取requestCode
【发布时间】:2012-11-15 04:32:57
【问题描述】:

是否可以在 Receiver 类或 Activity 类中在意图时获取 requestCode?​​p>

这是我的未决意图

alarmMgr= (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                Intent intent = new Intent(this, BroadcastReceiver_Class.class);
                /*intent.putExtra("alarm_time_minutes", minutes);*/
                pendingIntent = PendingIntent.getBroadcast(this, requestCode, intent,requestCode);
                alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);

提前致谢..

【问题讨论】:

    标签: android android-intent alarmmanager alarm android-pendingintent


    【解决方案1】:

    您可以将requestCode 附加到您的意图中。如下:

    intent.putExtra("requestCode", requestCode);
    

    然后你可以通过以下方式在Activity类中获取它:

    int requestCode = received_intent.getExtras().getInt("requestCode");  
    

    【讨论】:

    • 但是内置的android应用程序(例如相机和图库)如何知道您传递的请求代码? @克里姆
    • 为什么这种方法有效,它没有任何意义。 requestCode 参数将在方法PendingIntent.getBroadcast() 中变得多余
    • 实际上 PendingIntent.getBroadcast() 中的 requestCode 是有意义的,并为您提供了一个新的待处理意图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多