Android 调用其他应用的Activity并判断是否存在

方法1:

//第一个参数是Activity所在的package包名,第二个参数是完整的Class类名(包括包路径)
        ComponentName componetName = new ComponentName("com.gohoc.afinancegeek",
                "com.gohoc.afinancegeek.StartPageActivity");
        Intent intent = new Intent();
        intent.setComponent(componetName);
        startActivity(intent);

方法2:

调用方法:

        Intent intent = new Intent();
        intent.setAction("com.fid.band_module.ui.activity.lurk.LurkMainActivity");
        intent.addCategory("android.intent.category.DEFAULT");
        startActivity(intent);

检查第三方应用的Activity是否存在:

        //新版相机调用方式
        Intent newTakePhoto = new Intent();
        newTakePhoto.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
        newTakePhoto.putExtra(Constants.APP_NAME, getPackageName());
        newTakePhoto.putExtra(MediaStore.EXTRA_OUTPUT, getDiskCacheDir(this));
        newTakePhoto.putExtra(Constants.LEFT_TEXT_NEW, "取消");
        newTakePhoto.putExtra(Constants.RIGHT_TEXT_NEW, "保存");

        if(newTakePhoto.resolveActivity(getPackageManager()) != null){
            LogUtil.d(TAG, "用的是统一调起相机的方式");
            startActivityForResult(newTakePhoto, Constants.PHOTO_REQUEST_CODE);
        }

被调用Activity得在manifest添加如下信息:

        <activity
            android:name=".ui.activity.lurk.LurkMainActivity"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="com.fid.band_module.ui.activity.lurk.LurkMainActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容