用ZXing的demo写了一个程序,为什么用户需要选择,而不是调用自己的程序?求解决方法

enter image description here

用ZXing的demo写了一个程序,为什么用户需要选择,而不是调用自己的程序?求解决方法

因为你在AndroidManifest.xml文件中定义的过滤器的范围比较广,
调用程序时,系统会将所有相同类型的应用弹出,供你选择,
你可以定义一个比较特殊的过滤器来区别其他同类型的应用,
也可以如楼上所说调用时显示的指定应用的包名和类名。
例如Gallery3D的Activity中,每个intent-filter就是一个过滤器,你可以自己来定义,然后自己调用。


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

`<intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.view.urlimages" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
            <data android:mimeType="text/html" />
        </intent-filter>`

你想指定一个应用程序打开的话你把intent这样写:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            browserIntent.setClassName("package name ", "class name");
            browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);