简体   繁体   English

不了解 IntentFilters

[英]Not understanding IntentFilters

I am trying to copy a binary file (my own bespoke content, not a standard) from Google Drive to my app using the 'Send a Copy' menu item in Google Drive.我正在尝试使用 Google Drive 中的“发送副本”菜单项将二进制文件(我自己的定制内容,不是标准)从 Google Drive 复制到我的应用程序。

I had a look at the intent that Google Drive sends using Intent Intercept, and it basically is我查看了 Google Drive 使用 Intent Intercept 发送的 Intent,它基本上是

  • ACTION - android.intent.action.SEND行动 - android.intent.action.SEND
  • DATA - null数据 - 空
  • MIME - application/octet-stream MIME - 应用程序/八位字节流
  • URI - intent:#intent;action=android.intent.action.SEND;type=application/octet-stream;launchFlags=0x1b080000;end URI - 意图:#intent;action=android.intent.action.SEND;type=application/octet-stream;launchFlags=0x1b080000;end
  • FLAGS - FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET FLAG_ACTIVITY_FORWARD_RESULT FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT FLAG_ACTIVITY_PREVIOUS_IS_TOP FLAG_RECEIVER_FOREGROUND标志 - FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET FLAG_ACTIVITY_FORWARD_RESULT FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT FLAG_ACTIVITY_PREVIOUS_IS_TOP FLAG_RECEIVER_FOREGROUND
  • Extras - 1 Class: android.net.Uri$HierarchicalUri Key: android.intent.extra.STREAM Value: content://com.google.android.apps.docs.storage.legacy/enc%3Dy1Gjnka2NiGyk8sKV0CwRjnjL3WimTTirLdLn58FBZ7yVAJ2MPJNL_ZYQFzzl0a3pi0bnikAy29Y%0AcprYV_o8bxcPbb8r0Vv_wfq89BjBp1nQHOPUT8CiHQEzPwVwRhvByYmijg%3D%3D%0A附加功能 - 第1类:android.net.Uri $ HierarchicalUri重点:android.intent.extra.STREAM值:内容://com.google.android.apps.docs.storage.legacy/enc%3Dy1Gjnka2NiGyk8sKV0CwRjnjL3WimTTirLdLn58FBZ7yVAJ2MPJNL_ZYQFzzl0a3pi0bnikAy29Y%0AcprYV_o8bxcPbb8r0Vv_wfq89BjBp1nQHOPUT8CiHQEzPwVwRhvByYmijg%3D%3D %0A

The intent filter in my app's relevant activity is:我的应用相关活动中的意图过滤器是:

    <intent-filter>
        <action android:name="android.intent.action.SEND" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:mimeType="application/octet-stream" />
    </intent-filter>

and after some messing around it does now show up in the 'Send file with' list in Google Drive.经过一些混乱之后,它现在确实显示在 Google Drive 的“发送文件”列表中。

If I select my app as the target, it turns up in the onCreate() of the relevant activity, I can get the intent OK with getIntent(), but getData() - which is what I used to use with ACTION_VIEW intents from other places - returns null, probably not surprising as Data is listed as null in the intent above.如果我选择我的应用程序作为目标,它会出现在相关活动的 onCreate() 中,我可以使用 getIntent() 来确定意图,但是 getData() - 这是我曾经与其他人的 ACTION_VIEW 意图一起使用的位置 - 返回空值,可能并不奇怪,因为数据在上面的意图中被列为空值。

What I am not at all sure - with my limited knowledge and having read the 'Receiving simple data from other apps' documentation - is what to do next.我完全不确定 - 以我有限的知识并阅读了“从其他应用程序接收简单数据”文档 - 下一步该怎么做。 How do I get access to the file data so I can copy it?如何访问文件数据以便我可以复制它?

The next question, assuming I do succeed at that (with helpful answers), if I want to send multiple files at once from Google Drive, it looks to me that it will then use the SEND_MULTIPLE intent, so how would I access each files data then?下一个问题,假设我确实成功了(有有用的答案),如果我想从 Google Drive 一次发送多个文件,在我看来它将使用 SEND_MULTIPLE 意图,那么我将如何访问每个文件数据然后?

How do I get access to the file data so I can copy it?如何访问文件数据以便我可以复制它?

A Uri pointing to the shared content is in EXTRA_STREAM .指向共享内容的Uri位于EXTRA_STREAM Call getParcelableExtra() on the Intent to retrieve it.Intent上调用getParcelableExtra()来检索它。 You can then use a ContentResolver and openInputStream() to read in the content identified by that Uri .然后,您可以使用ContentResolveropenInputStream()读入由该Uri标识的内容。

How to obtain the value of the extra is covered by the documentation . 文档中介绍了如何获取 extra 的值。

it will then use the SEND_MULTIPLE intent, so how would I access each files data then?然后它将使用 SEND_MULTIPLE 意图,那么我将如何访问每个文件数据呢?

EXTRA_STREAM will now be a list of Uri values. EXTRA_STREAM现在将是一个Uri值列表。 Call getParcelableArrayListExtra() on the Intent to retrieve it.Intent上调用getParcelableArrayListExtra()来检索它。 You can then iterate over that list and use a ContentResolver and openInputStream() to get the content identified by the Uri .然后,您可以遍历该列表并使用ContentResolveropenInputStream()来获取由Uri标识的内容。

As before, how to obtain the value the extra is covered by the documentation .和以前一样, 文档中涵盖了如何获取 extra 的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM