如何启动和应用程序选择器 [英] How to start and App Chooser

查看:169
本文介绍了如何启动和应用程序选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void startImplicitActivation() {

Log.i(TAG, "Entered startImplicitActivation()");

// TODO - Create a base intent for viewing a URL 
// (HINT:  second parameter uses parse() from the Uri class)
Uri adress = Uri.parse(URL);
Intent intentUrlView = new Intent(Intent.ACTION_VIEW, adress);

// TODO - Create a chooser intent, for choosing which Activity
// will carry out the baseIntent. Store the Intent in the 
// chooserIntent variable below. HINT: using the Intent class' 
// createChooser())
Intent chooserIntent = Intent.createChooser(intentUrlView, CHOOSER_TEXT);
//chooserIntent = null;

Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
// TODO - Start the chooser Activity, using the chooser intent
if (intentUrlView.resolveActivity(getPackageManager()) != null) {
startActivity(chooserIntent);
}}

本申请的任务是隐式激活一个单独的应用程序来查看URLHTTP:// www.google.com。因此,应用程序选择器应该出现,让我选择betweent至少有两个浏览器:默认的,至极会告诉我的www.google.com网站,另一种简单的浏览器,至极只是表明我的网址。现在的问题是 - 应用程序选择器犯规出现,当我使用隐式的活动。也许我写wron意图过滤器的第二个简单的浏览器。

The task of this application is to implicitly activate a separate application to view the URL, "http:// www.google.com". So, App Chooser should appear and let me choose betweent at least two browsers: the default one, wich will show me the www.google.com site, and another simple "browser", wich just shows me the url. The problem is - App chooser doesnt appear, when i use implicit activity. Probably I wrote wron intent filters for second "simple browser".

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="course.labs.intentslab.mybrowser"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MyBrowserActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

            <!-- TODO - Add necessary intent filter information so that this
                            Activity will accept Intents with the 
                            action "android.intent.action.VIEW" and with an "http" 
                            schemed URL -->
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" />
        <category android:name="android.intent.category.BROWSABLE" />
        </activity>
    </application>

推荐答案

说真的,你有一个清单的GUI编辑器。

Seriously, you have a GUI editor for manifest.

<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.BROWSABLE" />

应该放在&LT;意向滤光器&gt; 标签,因为你已经可以在你的清单见。
像这样的:

should placed in <intent-filter> tag, as you already can see in your manifest. Like this:

<activity
    android:name=".MyBrowserActivity"
    android:label="@string/app_name" >

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

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

        <!-- TODO - Add necessary intent filter information so that this
                        Activity will accept Intents with the 
                        action "android.intent.action.VIEW" and with an "http" 
                        schemed URL -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>

</activity>


这是它的默认浏览器如何做的:


That is how it done in default browser:

        <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="http" />
            <data android:scheme="https" />
            <data android:scheme="about" />
            <data android:scheme="javascript" />
        </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:scheme="https" />
            <data android:scheme="inline" />
            <data android:scheme="file" />
            <data android:mimeType="text/html" />
            <data android:mimeType="text/plain" />
            <data android:mimeType="application/xhtml+xml" />
            <data android:mimeType="application/vnd.wap.xhtml+xml" />
        </intent-filter>

这篇关于如何启动和应用程序选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆