我阅读了Android文档,但我仍然需要更多的说明。PendingIntent到底是什么?


当前回答

一个PendingIntent是一个令牌,你给一个外部应用程序(例如NotificationManager, AlarmManager, Home Screen AppWidgetManager,或其他第三方应用程序),它允许外部应用程序使用你的应用程序的权限来执行预定义的代码段。

如果你给了外部应用一个Intent,它会用自己的权限执行你的Intent。但是如果你给了外部应用一个PendingIntent,该应用将使用你的应用权限执行你的Intent。

其他回答

顾名思义…PendingIntent

你可以过一段时间再做。这是另一个意图。它是一种将你的任务交给其他应用程序来执行的方式。

为什么需要PendingIntent ?我在想

为什么接收应用程序本身不能创建Intent或 为什么我们不能使用一个简单的意图达到同样的目的。

例如:Intent bluetoothIntent= new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

如果我将bluetoothIntent发送到另一个没有android。permission权限的应用程序。接收应用程序不能通过startActivity(bluetoothIntent)启用蓝牙。

使用PendingIntent可以克服这个限制。对于PendingIntent,接收应用程序不需要android.permission。BLUETOOTH_ADMIN用于开启蓝牙。源。

In an easy language, 1. A description of an Intent and Target action to perform. First you have to create an intent and then you have to pass an specific java class which you want to execute, to the Intent. 2. You can call those java class which is your class action class by PendingIntent.getActivity, PendingIntent.getActivities(Context, int, Intent[], int), PendingIntent.getBroadcast(Context, int, Intent, int), and PendingIntent.getService(Context, int, Intent, int); Here you see that Intent which is comes from the step 1 3. You should keep in mind that...By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified.

这是我读了很长时间后学到的。

PendingIntent基本上是一个包装另一个Intent对象的对象。然后它可以传递给一个外部应用程序,在那里你授予该应用程序执行操作的权利,即,执行意图,就像从你自己的应用程序的进程执行一样(相同的权限和身份)。出于安全原因,您应该始终将显式意图传递给PendingIntent,而不是隐式意图。

 PendingIntent aPendingIntent = PendingIntent.getService(Context, 0, aIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

悬而未决的意图

暂挂意图是对常规意图的包装 供另一个应用程序使用。 它使其他应用程序能够执行包含的功能 行动,因为它是你的应用程序与所有的权限 申请已获批准

当你想打开一些应用程序组件,如活动/服务/BroadcastReceiver在以后的时间或指定的时间间隔后,你必须发送PendingIntent在这种情况下。它就像你给其他应用程序一段时间后代表你运行你的应用程序代码的许可条。因此,PendingIntent可以超越进程边界,比如你想要AlarmManager,这是另一个进程中的另一个应用程序,然后AlarmManager在你的应用程序上执行由PendingIntent指定的操作