Android API below 19 equivalent for ContentResolver takePersistableUriPermission

浪尽此生 提交于 2019-12-24 17:17:15

问题


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);
}

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,


回答1:


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.



来源:https://stackoverflow.com/questions/30424473/android-api-below-19-equivalent-for-contentresolver-takepersistableuripermission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!