Alexander Fuchs
Alexander Fuchs

Reputation: 1358

Android Intent Filter zip

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();
        }

Upvotes: 5

Views: 4182

Answers (1)

Gubbel
Gubbel

Reputation: 2406

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());

Upvotes: 8

Related Questions