其他分享
首页 > 其他分享> > Android Intent Filter zip

Android Intent Filter zip

作者:互联网

我想使用一个Intent过滤器,当在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>

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

解决方法:

您可以使用以下IntentFilter:

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

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

    <data android:mimeType="application/zip"/>
</intent-filter>

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

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

标签:android,zip,android-intent,intentfilter
来源: https://codeday.me/bug/20190902/1790542.html