3

So, I want my app to be able to upload files that the user shares with it. I got it to handle files shared from my various file explorers through file:// urls, then handling things shared from, say, the Gallery via content:// URLs. All good, except then I randomly decided to test sharing from the DownloadManager.

Here's the code:

@Override
protected void onNewIntent(Intent intent) {

super.onNewIntent(intent);

if(intent.getAction() == Intent.ACTION_SEND) {
    Uri fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if(fileUri != null) {

        if(fileUri.getScheme().equals("content")) {
            try {
                Uri data = intent.getData();
                InputStream input = getContentResolver().openInputStream(fileUri);
                //Do something with InputStream
            } catch(Exception e) {
                //Log exception/show error
            }

        }

    }
}
}

However, whenever I try to pass the Uri "data" into openInputStream I get a NullPointerException as getData() is returning null, even though other questions I've seen on this topic have said to use getData().

And when I try to pass "fileUri" into openInputStream, as I'm doing in the code I get the security exception:

06-20 12:41:24.310: E/AndroidRuntime(12375): java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/433 from pid=12375, uid=10212 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()

I've tried adding this permission but I'm aware that it isn't open for any app to use.

So, I have no idea how else to try and pull the file data out of the Intent, hopefully there's something obvious that I'm missing.

4

0 回答 0