其他分享
首页 > 其他分享> > Android文件关联不起作用(意图过滤器,按扩展名)

Android文件关联不起作用(意图过滤器,按扩展名)

作者:互联网

我一直在尝试将我的应用与vrtci文件扩展名相关联,但无法正常工作.我一直在互联网上寻找自己做错了什么,但没有任何帮助.这是我的AndroidManifest.xml中的部分:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light">
    <activity
        android:name=".MainCardActivity"
        android:label="@string/app_name"
        android:configChanges="keyboardHidden|orientation|screenSize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".CardInstaller" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="content" />
            <data android:pathPattern=".*\\.vrtci" />
            <data android:mimeType="application/octet-stream" />
        </intent-filter>
        <!-- For http -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.vrtci" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <!-- For https -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="https" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.vrtci" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <!-- For file browsers and google drive -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.vrtci" />
            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>
</application>

解决方法:

因此,我刚刚找到了一个对我有用的解决方案.

使用方案“ content”创建意图过滤器,根本不指定host元素.

     <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="content" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\.vrtci" />
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.vrtci" />
        </intent-filter>

标签:associations,file-extension,android
来源: https://codeday.me/bug/20191121/2049208.html