IntentSender的目的是什么?

时间:2012-03-06 11:55:34

标签: android android-intent

我想知道IntentSender类对我们的应用程序的目的是什么?我们如何在我们的应用程序中使用它?

除了The Android Intent Based APIs: Part Seven – IntentSenders And PendingIntents之外,还有什么好的例子吗?

2 个答案:

答案 0 :(得分:11)

IntentSender是一种抽象或胶水等级,允许你

  1. 当用户在选择器中选择应用程序时接收广播。

    使用IntentSender时的示例:

    Intent intent = new Intent(Intent.ACTION_SEND)
        .putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
        .setType("text/plain");
    Intent receiver = new Intent(this, BroadcastTest.class)
        .putExtra("test", "test");
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent chooser = Intent.createChooser(intent, "test", pendingIntent.getIntentSender());
    startActivity(chooser);
    
  2. 使用Activity代替IntentSender开始IntentAndroid docs中的更多内容)

      

    startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)

         

    startActivity(Intent, Bundle)类似,但需要IntentSender开始。

答案 1 :(得分:2)

IntentSender的官方Android开发人员文档明确指出:

  

此类的实例不能直接创建,而是必须使用PendingIntent从现有PendingIntent.getIntentSender()创建。

因此,您(应该)不会在代码示例或教程中直接使用此类。

对于PendingIntent,它基本上是您提供给另一个应用程序的令牌,该应用程序允许该应用程序使用您应用程序的权限来执行应用程序代码的特定部分。

Here's an example在课程中使用的PendingIntent

相关问题