2013年8月19日 星期一

Start an APP from another APP in Android

The following is the snippet for testing:

import android.content.pm.ResolveInfo;
import java.util.List;


if (keyCode == KeyEvent.KEYCODE_GREEN) {
             Log.d(TAG, "green key is triggered");
             Intent hotkey_intent = new Intent("android.intent.action.MAIN");
             hotkey_intent.addCategory("android.intent.category.LAUNCHER");

             List<ResolveInfo> resolveinfo_list = mContext.getPackageManager().queryIntentActivities(hotkey_intent, 0);

             for(ResolveInfo info:resolveinfo_list){
                 Log.d(TAG, info.activityInfo.packageName);
                 if(info.activityInfo.packageName.equalsIgnoreCase("com.android.settings")){
                     hotkey_intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                     hotkey_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                     mContext.startActivity(hotkey_intent);
                     break;
                 }
             }
         }


settings APP is brought up when GREEN key is pressed.

Action and category seem to work as filters for the activities it searches. In order to get a full list of APPs, I perhaps have to change them.

Reference links
http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent

沒有留言:

張貼留言