Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
        }
like image 849
Alexander Fuchs Avatar asked Mar 08 '12 18:03

Alexander Fuchs


1 Answers

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());
like image 73
Gubbel Avatar answered Nov 08 '22 06:11

Gubbel