今天主要分析创建shortcut、widget流程。
创建ShortCut流程,首先看completeAdd函数。
private boolean completeAdd(PendingAddArguments args) {
boolean result = false;
switch (args.requestCode) {
......
case REQUEST_PICK_SHORTCUT:
processShortcut(args.intent);
break;
......
}
resetAddInfo();
return result;
}
在completeAdd里接收到REQUEST_PICK_SHORTCUT请求,执行processShortcut()创建shortcut
void processShortcut(Intent intent) {
String applicationName = getResources().getString(R.string.group_applications);//applicationName是apps
String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
if (applicationName != null && applicationName.equals(shortcutName)) {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);//选择应用
pickIntent.putExtra(Intent.EXT