打开第三方应用

时间:2014-04-28 10:25:41   收藏:0   阅读:400

记录一下,自己用过的打开第三方应用的两种方法;


1.//根据包名类名启动第三方应用(要启动的应用的包名,要启动的activity)

openApp("com.xx.test", "com.xx.test.TestActivity");

   private void openApp(String pname,String aname){
//      changeInputSource(pname);
        ComponentName componentName = new ComponentName(pname,
                aname);
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        try {
            mContext.startActivity(intent);
        } catch (ActivityNotFoundException anf) {
            Toast.makeText(mContext, "找不到应用数据", Toast.LENGTH_SHORT).show();
        }
    }
2.//根据Action启动应用

startApp("com.xx.test.action");

	private void startApp(String action){
	    Intent pointIntent = new Intent(action);
        pointIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        try {
            mcontext.startActivity(pointIntent);
        } catch (ActivityNotFoundException anf) {
            Toast.makeText(mcontext, R.string.notfind, Toast.LENGTH_SHORT).show();
        }               //R.string.notfind = "找不到应用数据"

	}


打开第三方应用,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!