I have defined the following Intent filter in my manifest which allows me to open .ips files that are downloaded from the browser and also from email attachments.
<intent-filter
android:icon='@drawable/ic_launcher'
android:label="@string/quick_patcher_label"
android:priority='1'>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="*/*" />
<data android:pathPattern="*.ips" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="*/*" android:scheme="http" android:host="*" android:pathPattern=".*\\.ips" />
<data android:mimeType="*/*" android:scheme="https" android:host="*" android:pathPattern=".*\\.ips" />
</intent-filter>
I tried part of the answer for this question which resulted in "false" as the file name, and I tried this one too. How can I retrieve the file path of the file I've opened with this intent filter from within my activity?
EDIT: Found this in another question, it works when opening from downloads but gives a NullPointerException for opening from emails. Anyone know why that is?
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
How can I retrieve the file path of the file I've opened with this intent filter from within my activity?
There might not be a "file path". You use getIntent().getData()
to get the Uri
of the data. Then, use ContentResolver
and openInputStream()
to get an InputStream
for the data from that Uri
.
From emails, you are probably getting EXTRA_TEXT and not a STREAM. So the STREAM comes out null.
Emails never exist as a file. You can save them to a file. But then they are no longer an email.
So, next time you are asked: "When is an email not an email?", you will know the answer and the asker will bow to your superior wisdom and ask to be your disciple. But I digress...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.