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

时间:2014-10-30 22:19:33

标签: android associations file-extension

我一直在尝试将我的应用与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>

1 个答案:

答案 0 :(得分:3)

所以我刚刚找到了一个解决方案,它为我做了。

使用scheme&#34; content&#34;创建intent-filter;并且根本不指定主机元素。

     <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>