【问题标题】:What permissions does an activity or application need to start another activity?一个活动或应用程序需要哪些权限才能启动另一个活动?
【发布时间】:2015-08-11 15:06:42
【问题描述】:

我到处读到,使用 pendingIntent 是为了允许另一个应用程序获得启动在另一个应用程序代码中实例化的 Intent 所需的权限。这些权限是什么?使用 pendingIntent 有什么帮助?

在pendingIntents上引用另一个答案:

“PendingIntent 是您提供给外部应用程序(例如 NotificationManager、AlarmManager、Home Screen AppWidgetManager 或其他 3rd 方应用程序)的令牌,它允许外部应用程序使用您的应用程序的权限来执行预定义的一段代码。"

【问题讨论】:

标签: android


【解决方案1】:

如果我们使用 PendingIntent,使用该意图的应用程序不需要拥有该权限。但是创建 PendingIntent 的应用程序肯定要有 Intent 所需的权限。

我在评论中发布的link 给出了一个非常清楚的例子。

应用程序 A 有权读取用户的联系人但 B 才不是。在这种情况下,如果特权应用程序 A 提供应用程序 B 一个待处理的意图,以便 B 在它想要读取 a 时可以发送它 联络资料。 A 有责任询问用户 用户想要提供给 B 的联系人数据,并且只提供 B 该数据。 用户有责任决定应用程序 B 对于用户选择的联系人数据是否可信。

【讨论】:

  • 当一个应用程序需要启动另一个应用程序的活动时怎么办?因此,创建了一个pendingIntent 来启动属于另一个应用程序的活动。在这种情况下,需要哪些权限?
  • 要启动其他应用程序的活动,您不需要任何特殊权限。
  • 使用通知时,我们会这样做。例如这里: Intent intent = new Intent(this,MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
  • 点击通知时必须发送 Intent“intent”。
  • 在上面的示例中,您根本没有指定任何权限。您正在使用 developer.android.com/reference/android/app/…, int, android.content.Intent, int) 创建 PendingIntent 的版本,您指定的只是上下文、请求代码、意图和标志。没有任何权限。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-22
  • 2013-02-17
  • 2015-09-29
  • 2014-06-18
  • 2011-01-13
  • 1970-01-01
相关资源
最近更新 更多