利用Intent隐式跳转,实现手动选择打开符合条件的应用程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhuchenglin830/article/details/82533305

先看实现效果:

实现如上图一样的效果,可以手动选择打开手机上符合条件的应用程序,用于程序中的一些功能,比如程序中分享功能,将手机上符合分享条件的所有程序弹出来供使用人手动选择;再比如手机白名单的实现!

实现原理:使用Intent的隐示意图跳转实现,具体代码如下

AndroidManifest.xml中的配置

<activity android:name=".thirdpartyActicity.OKHttpUtilsActivity">
            <intent-filter>
                <action android:name="okhttpUtils" />

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

action中填写自定义的名称,这个名称为过滤的内容之一,当两个程序的name一样时,在跳转的时候,实现上述效果;

category中使用默认值即可

Activity.java中intent代码如下:

​
        Intent intent = new Intent();
        intent.setAction(action);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        startActivity(intent);

​

intent跳转时会与AndroidManifest.xml中的activity的action进行对比,一致时会自动跳转,当多个程序的action一致时,则会自动弹出选择,

根据上述原理,也可实现本程序中,根据action不同跳转不同的页面,在AndroidManifest.xml中,给不同的activity配置不同的action,在跳转位置,只需要写几句简单的跳转代码,即可实现自动跳转到不同页面!

注意:AndroidManifest.xml中的activity的action区分大小写,必须与Activity.java中的intent中的action完全一致

猜你喜欢

转载自blog.csdn.net/zhuchenglin830/article/details/82533305
今日推荐