添加应用桌面快捷方式的方法

来源:互联网 发布:centos 内核降级 编辑:程序博客网 时间:2024/05/16 06:38

实现效果:长按实现添加桌面快捷方式

代码:

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方式获得快捷方式的图标。

0 0
原创粉丝点击