My application is configured to activate after opening a file with the extension .myappdata. He does this through this filter intent:
<activity android:name="com.myapp.ExamineFileActivity"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="file" android:pathPattern=".*\\.myappdata" android:mimeType="*/*"/> <data android:scheme="content" android:pathPattern=".*\\.myappdata" android:mimeType="*/*"/> </intent-filter> </activity>
I open the Chrome browser (on Nexus 7 running Android 6.0.1) and go to the website downloading the file called "file123.myappdata" and click the "Open" link in Chrome.
This action launches my application to open and runs this code that will load the downloaded file name:
Uri uri = this.getIntent().getData(); if (uri.getScheme().equals("content")) { Cursor cursor = getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { return cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } finally { cursor.close(); } }
when this code is run (after I open the file from Chrome) uri is content: // downloads / my_downloads / 1602 and cursor.moveToFirst () returns false
Then I exit my application and go to the Downloads application and open the same file. This launches my application to open, the same code runs, except for the contents of uri: // downloads / all_downloads / 1602 (everything else in the uri is exactly the same), calling cursor.moveToFirst () returns true , and the cursor.getString () method returns "file123.myappdata" (which is exactly what I want).
Why does the cursor.moveToFirst () method not find any data when I open the downloaded file from Chrome (giving me "my_downloads" in the uri) compared to opening the same downloaded file from the downloads (giving me "all_downloads" in the URI)?
source share