Android 快捷启动图标

来源:互联网 发布:brew mysql 编辑:程序博客网 时间:2024/06/02 03:08

Android 快捷启动图标

核心代码

Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//不允许重复创建shortcut.putExtra("duplicate", false)//需要实现的名称shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, strName);//快捷图片Parcelable icon = Intent.ShortcutIconResource.formContext(context, iconResId);shortcut.putExtra(Intent.EXTRA_SHORTCUT_RESOURCE, icon);//点击快捷图片,运行程序Intent intent = new Intent(context.getApplicationContext(),MainActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//Android启动模式 清除当前activity main 及以上的 activity 并从新创建 MainActivity;shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

需要注意

被启动的 activity 必须是默认启动的ac

  <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>
原创粉丝点击