首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >com.google.android.apps.nbu.files.provider/2是什么?

com.google.android.apps.nbu.files.provider/2是什么?
EN

Stack Overflow用户
提问于 2021-05-21 14:05:27
回答 1查看 5.9K关注 0票数 3

我已经从不同的来源打开了pdf文件并得到了这个Intents

Intent { act=android.intent.action.VIEW dat=content://com.google.android.apps.nbu.files.provider/1/file:///storage/emulated/0/Download/Untitled.pdf typ=application/pdf flg=0x13000001 cmp=team.sls.testapp/.ActivityMain }

  1. 文件管理器(Google ) ->内部存储->下载:

Intent { act=android.intent.action.VIEW dat=content://com.google.android.apps.nbu.files.provider/2/1863 typ=application/pdf flg=0x13000001 cmp=team.sls.testapp/.ActivityMain }

  1. 文件管理器(Google ) ->下载

Intent { act=android.intent.action.VIEW dat=content://com.android.providers.downloads.documents/document/1508 typ=application/pdf flg=0x13000003 cmp=team.sls.testapp/.ActivityMain } (来自通知面板):

  1. 下行负载管理器

Intent { act=android.intent.action.VIEW dat=content://org.telegram.messenger.provider/media/Telegram/Telegram Documents/2_5276292126848585208.pdf typ=application/pdf flg=0x13000001 cmp=team.sls.testapp/.ActivityMain }

  1. 电话聊天

什么是content://com.google.android.apps.nbu.files.provider/2/1863,为什么到同一个文件的路径是不同的?但是更有趣的是--为什么案例1和4可以打开带有自定义扩展名的文件,但是2和3不能打开?

如果对案例1和例2有误解,请查看this question中的屏幕截图

EN

回答 1

Stack Overflow用户

发布于 2021-06-28 23:48:57

这四个Uri都遵循相同的模式

代码语言:javascript
运行
复制
content://com.google.android.apps.nbu.files.provider/1/file:///storage/emulated/0/Download/Untitled.pdf
content://com.google.android.apps.nbu.files.provider/2/1863
content://com.android.providers.downloads.documents/document/1508
content://org.telegram.messenger.provider/media/Telegram/Telegram Documents/2_5276292126848585208.pdf

content://PACKAGE_NAME.provider/CONTENT_DETAIL

显然,application.

  • And依赖于,CONTENT_DETAIL是可选的,无论是file_id还是full_path.。

如果您对这四个应用程序进行反编译,并查看它们的AndroidManifest.xml,您将看到相同的提供者标记,但差别很小。

看看Google的AndroidManifest.xml

代码语言:javascript
运行
复制
<application>
  <provider 
    android:name="com.google.android.libraries.storage.storagelib.FileProvider" 
    android:exported="false" 
    android:authorities="com.google.android.apps.nbu.files.provider" 
    android:grantUriPermissions="true"/>
</application>

此提供程序将生成类似于下面的HierarchicalUricontent://com.google.android.apps.nbu.files.provider/1651/2

使用下面的代码片段,您可以从所有这四个应用程序中读取文件/内容。

代码语言:javascript
运行
复制
public final class MainActivity extends AppCompatActivity{

   @Override
    protected void onCreate(Bundle savedInstanceState) {
      Intent intent = getIntent();
      InputStream is = getContentResolver().openInputStream(intent.getData());
      String content = new String(Utils.unwrap(is));
      Log.i("TAG", "content: " + content);
   }

   public static byte[] unwrap(InputStream is) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int nRead;
        byte[] data = new byte[4096];
        while ((nRead = is.read(data, 0, data.length)) != -1) {
            baos.write(data, 0, nRead);
        }
        baos.flush();
        is.close();
        baos.close();
        return baos.toByteArray();
   }
}

我希望我已经回答了你的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67638455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档