I want to use a Intent-filter , that makes the application open when a zip file is clicked in a fileexplorer
so which mimetype do i have to use ? and what codee to get the path?
<activity
android:name=".App"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
Java-Code:
Intent intent = getIntent();
// To get the action of the intent use
String action = intent.getAction();
if (action != Intent.ACTION_SEND) {
throw new RuntimeException("Should not happen");
}
// To get the data use
Uri data = intent.getData();
URL url;
try {
url = new URL(data.getPath());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
You can use the following IntentFilter
:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/zip"/>
</intent-filter>
When your Activity is started, it has a data URI
from which you can get the zip file:
File zip = new File(getIntent().getData().getPath());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With