Android Intent Filter zip

Ale*_*chs 3 zip android intentfilter android-intent

我想使用Intent-filter,当在fileexplorer中单击一个zip文件时,它会打开应用程序

所以我必须使用哪种mimetype?以及获得路径的代码?

<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>
Run Code Online (Sandbox Code Playgroud)

Java的代码:

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();
        }
Run Code Online (Sandbox Code Playgroud)

Gub*_*bel 5

您可以使用以下内容IntentFilter:

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>

    <category android:name="android.intent.category.DEFAULT"/>

    <data android:mimeType="application/zip"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

当您的Activity启动时,它有一个数据URI,您可以从中获取zip文件:

File zip = new File(getIntent().getData().getPath());
Run Code Online (Sandbox Code Playgroud)

  • Android 5.0上的mimeType是"application/x-zip-compressed" (2认同)