将应用程序与文件扩展名关联 - 意图过滤器不工作?

时间:2013-03-15 22:13:49

标签: java android pdf android-intent associate

我希望我的应用程序位于列表中,以便在android环境中的任何位置打开pdf。我环顾四周,根据我读过的内容添加了这些意图。但是,在测试和打开pdf时,只需使用默认应用程序polaris打开它?

据我了解,在活动中我使用下面的代码来传递信息。

Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();

我尝试解除Polaris,然后打开它时说无法找到执行此应用程序的应用程序。

<activity
        android:name=".UserLogIn"
        android:label="User Authentication" >
        <intent-filter>
            <action android:name="com.example.USERLOGIN" />

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

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

            <data android:scheme="http" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.pdf" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

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

            <data android:scheme="http" />
            <data android:host="*" />
            <data android:mimeType="application/pdf" />
        </intent-filter>
        <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=".*\\.pdf" />
        </intent-filter>
</activity>

1 个答案:

答案 0 :(得分:1)

这适合我的:

    <activity
        android:name=".ui.PdfViewerActivity" >
        <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:mimeType="application/pdf" />
        </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:host="*" />
            <data android:scheme="file" />
            <data android:scheme="smb" />
            <data android:scheme="content" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.pdf" />
        </intent-filter>
    </activity>
相关问题