3

I have an app that allows adding hyperlinks to content on the device. To pick and URI I do this:

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        if (Build.VERSION.SDK_INT >= 11)
            intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(Intent.createChooser(intent, getString("hyperlink")), ACTIVITY_RESULT_SELECT_URI_LINK);
}

In onActivityResult I store the returned Uri like so:

uri = Uri.parse(data.getDataString());
if (Build.VERSION.SDK_INT >= 19) {
  final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  getContentResolver().takePersistableUriPermission(uri, takeFlags);
}

When the user invokes the link from inside my app, I do basically this:

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(uri);
        intent = Intent.createChooser(intent, context.getResources().getString("open"));
        if (intent != null)
            context.startActivity(intent);

Up to android 4.4 this all worked fine. However, since android 4.4 this no longer works. I have read about the new DocumentProviders and permissions: https://developer.android.com/guide/topics/providers/document-provider.html#permissions and as you can see above, I do attempt to persist the permissions, but no Uri will open like this anymore. Opening an image in Galery I get an empty screen and in LogCat I see

W/SurfaceFlinger(122): couldn't log to binary event log: overflow.

For videos I get something like (translated) cannot play back this video.

As said, this all used to work until android 4.4.

I have tried to use ACTION_OPEN_DOCUMENT rather than ACTION_GET_CONTENT like so:

        intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.setType("*/*");
        // intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        intent.addCategory(Intent.CATEGORY_OPENABLE);

But that does not make a difference. Any idea how to get this working: Pick an Uri to anything on the device and at a later time open it?

Similar, but not completely identical to: New KitKat URIs dont respond to Intent.ACTION_VIEW

Thanks in advance.

Community
  • 1
  • 1
Gerrit Beuze
  • 903
  • 2
  • 10
  • 26

0 Answers0