Android Intent Filter zip

I want to use an intent filter that makes the app open when clicking on a zip file in fileexplorer

so what mimetype do I need to use? and which 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();
        }

      

+3


source to share


1 answer


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 data URI

from which you can get a zip file:

File zip = new File(getIntent().getData().getPath());

      

+5


source







All Articles