Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何启动和安装应用程序选择器_Android - Fatal编程技术网

Android 如何启动和安装应用程序选择器

Android 如何启动和安装应用程序选择器,android,Android,此应用程序的任务是隐式激活单独的应用程序以查看URL“http://www.google.com”。因此,appchooser应该出现,让我在至少两个浏览器中进行选择:默认的一个,它将显示www.google.com网站,另一个简单的“浏览器”,它只显示url问题是-当我使用隐式活动时,应用程序选择器没有出现。可能是我为第二个“简单浏览器”编写了错误的意图过滤器 清单 <manifest xmlns:android="http://schemas.android.com/apk/res/

此应用程序的任务是隐式激活单独的应用程序以查看URL“http://www.google.com”。因此,appchooser应该出现,让我在至少两个浏览器中进行选择:默认的一个,它将显示www.google.com网站,另一个简单的“浏览器”,它只显示url问题是-当我使用隐式活动时,应用程序选择器没有出现。可能是我为第二个“简单浏览器”编写了错误的意图过滤器

清单

 <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编辑器

这个


应该放在
标记中,正如您在清单中已经看到的那样。 像这样:

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


这就是在默认浏览器中的操作方式:

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

我是这样做的:

步骤1:首先在字符串中

<string name="webklink">&lt;a href="http://www.google.com">SomeLink&lt;/a></string>

希望这能有所帮助:

似乎是亚当·波特第三周的任务,为Android手持系统编程移动应用程序。 不管怎样,我希望你有你的解决办法 在AndroidManifest.xml中,您需要再添加三个意图过滤器

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

Coursera已经有了邮件列表。请使用它。

多操作应用程序选择器的简单实现:

Intent phoneCall = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", contactNumber, null));
// Intent sms = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + contactNumber));
Intent whatsapp = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + contactNumber));
Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, Calendar.getInstance().getTimeInMillis());
Intent calendarIntent = new Intent(Intent.ACTION_VIEW).setData(builder.build());

Intent chooser = Intent.createChooser(whatsapp, "chooser??"); // default action
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{phoneCall, calendarIntent}); // additional actions
startActivity(chooser);

在运行
lab3a\u-MyBrowser
之前,必须先运行
lab3a\u-IntentsLab
,以便在手机上安装浏览器。然后,您的选择者就可以看到它。

非常感谢您!我还没有认识到这种愚蠢的错误是因为疲劳。但是,即使在修复之后,我的程序仍然不起作用。若你们包括了类别,所有符合目的过滤器的目的都必须设置这个类别。您的代码未设置必需的类别,因此您的意图与筛选器不匹配。阅读文档中意图过滤器的工作原理“只有当意图可以通过其中一个意图过滤器时,系统才会向应用程序组件传递隐含意图。”-据我所知,如果应用程序通过和操作意图过滤器,那么它将在应用程序选择器中显示。但是我删除了category字段,我查看了文档,在清单文件中找不到问题。现在我确信问题出在浏览器应用程序中。我已经安装了opera mini和chrome,我看到了包含它们的App chooser,但不是那个应用。谢谢!我刚刚添加了一个默认类别,它现在可以工作了。这里的解释是:“为了接收隐式意图,您必须在意图过滤器中包含category_default category。方法startActivity()和startActivityForResult()将所有意图视为它们声明了类别默认值。如果您没有在意图过滤器中声明,则不会对您的活动解析任何隐含意图。“我不明白为什么对上述答案投反对票。它非常好,并且按照问题的要求运行良好。如果有人投了反对票,应该在评论框中说明原因。这是马里兰安卓类课程coursera上的第一部分…+1“似乎是亚当·波特第三周为安卓手持系统编程移动应用程序的作业”:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/webklink"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>
public class OpenWeb extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webopen);

        TextView someLink = (TextView)findViewById(R.id.textView1);
        if(someLink!=null){

            someLink.setMovementMethod(LinkMovementMethod.getInstance());
            someLink.setText(Html.fromHtml(getResources().getString(R.string.webklink)));
        }

    }
}
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
Intent baseIntent = new Intent(Intent.ACTION_VIEW);
        baseIntent.setData(Uri.parse(URL));

Intent chooserIntent = Intent.createChooser(baseIntent, "Select Application");
Intent phoneCall = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", contactNumber, null));
// Intent sms = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + contactNumber));
Intent whatsapp = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + contactNumber));
Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, Calendar.getInstance().getTimeInMillis());
Intent calendarIntent = new Intent(Intent.ACTION_VIEW).setData(builder.build());

Intent chooser = Intent.createChooser(whatsapp, "chooser??"); // default action
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{phoneCall, calendarIntent}); // additional actions
startActivity(chooser);