适用于ContentResolver的19以下版本的Android API takePersistableUriPermission [英] Android API below 19 equivalent for ContentResolver takePersistableUriPermission

查看:324
本文介绍了适用于ContentResolver的19以下版本的Android API takePersistableUriPermission的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用它来让用户选择文件,选择之后,我仅将文件的URI存储在共享首选项中.将来用户可以打开该文件-所以我有了URI,因此可以完成

I use this to let the user select file, after the selection I store in shared prefs only the URI of the file. In the future the user can open this file - So I have the URI and therefore it can be done

        final Intent intent = new Intent();
        if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= 19) {
            intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        }     
        else {
            intent.setAction(Intent.ACTION_GET_CONTENT);
        }        
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("application/msword,application/pdf,text/plain");  //Text, DOC, PDF
        startActivityForResult(intent, READ_REQUEST_CODE);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
    //Get and Store the URI in shared prefs...
    final int takeFlags = data.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION
                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    getContentResolver().takePersistableUriPermission(uri, takeFlags);
}

最后一行代码(如果我理解正确,则保存了读取权限以供以后使用)仅在API 19及更高版本上有效. API 19下的等效项是什么? 总的来说,问题是如何以这种方式在19岁以下的API中获得持久性网络许可?谢谢,

The last line of code (which if I understood correctly saving the read permission for later use) working only from API 19 and above. What is the equivalent for this below API 19? In general, the question is how to obtain in this pattern the persistnet permission in API`s below 19? Thanks,

推荐答案

API 19之下的等效项是什么?

What is the equivalent for this below API 19?

除了在您自己的应用程序中将内容复制为本地文件外,没有任何内容.

There is none, short of making a copy of the content as a local file within your own app.

这篇关于适用于ContentResolver的19以下版本的Android API takePersistableUriPermission的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆