본문 바로가기
안드로이드

[안드로이드] 특정 App의 Main Activity 실행하기

by 호군 2012. 1. 10.
반응형

⊙ 소스코드
  
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
       
        final PackageManager packageManager = getPackageManager();
        apps = packageManager.queryIntentActivities(mainIntent, 0);
       
        if (null != apps) {
         Log.d("ACTIVITY", "apps : " + apps.size());
         ResolveInfo info = apps.get(0);
         String pkg = info.activityInfo.applicationInfo.packageName;
         String cls = info.activityInfo.name;
         ComponentName componentName = new ComponentName(
                    info.activityInfo.applicationInfo.packageName,
                    info.activityInfo.name);
         
         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);
           
            startActivity(intent);
        }
       
반응형