private void addShortcut(LayoutElementParcelable path) {
//Adding shortcut for MainActivity
//on Home screen
final Context ctx = getContext();
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(ctx)) {
Toast.makeText(getActivity(),
getString(R.string.addshortcut_not_supported_by_launcher),
Toast.LENGTH_SHORT).show();
return;
}
Intent shortcutIntent = new Intent(ctx, MainActivity.class);
shortcutIntent.putExtra("path", path.desc);
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Using file path as shortcut id.
ShortcutInfoCompat info = new ShortcutInfoCompat.Builder(ctx, path.desc)
.setActivity(getMainActivity().getComponentName())
.setIcon(IconCompat.createWithResource(ctx, R.mipmap.ic_launcher))
.setIntent(shortcutIntent)
.setLongLabel(path.desc)
.setShortLabel(new File(path.desc).getName())
.build();
ShortcutManagerCompat.requestPinShortcut(ctx, info, null);
}
MainFragment.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:AmazeFileManager
作者:
评论列表
文章目录