实现效果:长按实现添加桌面快捷方式
代码:
public class OnShortcutListener implements OnItemLongClickListener {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Intent intentAddShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, “name”);
Parcelable icon;
intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.ic_launcher);
Intent intentLauncher = new Intent();
intentLauncher.setClass(getBaseContext(), AppViewerActivity.class);
//以下代码实现在桌面点击快捷方式,进入网页的效果
SubApp subapp=subApps.get(position);
Uri uri;
if (subapp.isRemote() == false)
uri=Uri.parse("file:///" + subapp.getAppFolderName()
+ File.separator + subapp.getName());
else
uri=Uri.parse(subapp.getName());
intentLauncher.setData(uri);
intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intentLauncher);
sendBroadcast(intentAddShortcut);
return true;
}
}
正在研究如何通过图片路径或Bitmap方式获得快捷方式的图标。