JavaShuo
栏目
标签
Android Create Shortcut 桌面 快捷方式 图标
时间 2019-11-18
标签
android
create
shortcut
桌面
快捷方式
图标
栏目
Android
繁體版
原文
原文链接
Add permission:
html
[html]
view plain
copy
<EMBED id=ZeroClipboardMovie_1 height=18 name=ZeroClipboardMovie_1 type=application/x-shockwave-flash align=middle pluginspage=http://www.macromedia.com/go/getflashplayer width=18 src=http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf wmode="transparent" flashvars="id=1&width=18&height=18" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" quality="best" menu="false" loop="false">
<
uses-permission
android:name
=
"com.android.launcher.permission.INSTALL_SHORTCUT"
/>
<
uses-permission
android:name
=
"com.android.launcher.permission.UNINSTALL_SHORTCUT"
/>
Code:
java
[java]
view plain
copy
<EMBED id=ZeroClipboardMovie_2 height=18 name=ZeroClipboardMovie_2 type=application/x-shockwave-flash align=middle pluginspage=http://www.macromedia.com/go/getflashplayer width=18 src=http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf wmode="transparent" flashvars="id=2&width=18&height=18" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" quality="best" menu="false" loop="false">
private
void
setUpShortCut() {
Intent intent =
new
Intent(CREATE_SHORTCUT_ACTION);
// 设置快捷方式图片
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(
this
, R.drawable.logo));
// 设置快捷方式名称
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
"sina"
);
// 设置是否容许重复建立快捷方式 false表示不容许
intent.putExtra(
"duplicate"
,
false
);
// 设置快捷方式要打开的intent
// 第一种方法建立快捷方式要打开的目标intent
Intent targetIntent =
new
Intent();
// 设置应用程序卸载时同时也删除桌面快捷方式
targetIntent.setAction(Intent.ACTION_MAIN);
targetIntent.addCategory(
"android.intent.category.LAUNCHER"
);
ComponentName componentName =
new
ComponentName(getPackageName(),
this
.getClass().getName());
targetIntent.setComponent(componentName);
// 第二种方法建立快捷方式要打开的目标intent
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
// 发送广播
sendBroadcast(intent);
}
private
void
tearDownShortCut() {
Intent intent =
new
Intent(DROP_SHORTCUT_ACTION);
// 指定要删除的shortcut名称
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
"sina"
);
String appClass = getPackageName() +
"."
+
this
.getLocalClassName();
ComponentName component =
new
ComponentName(getPackageName(), appClass);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new
Intent().setAction(Intent.ACTION_MAIN).setComponent(component));
sendBroadcast(intent);
}
Or:
android
[java]
view plain
copy
<EMBED id=ZeroClipboardMovie_3 height=18 name=ZeroClipboardMovie_3 type=application/x-shockwave-flash align=middle pluginspage=http://www.macromedia.com/go/getflashplayer width=18 src=http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf wmode="transparent" flashvars="id=3&width=18&height=18" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" quality="best" menu="false" loop="false">
if
(Intent.ACTION_CREATE_SHORTCUT.equals(action))
{
setupShortcut();
finish();
return
;
}
...
private
void
setupShortcut() {
// First, set up the shortcut intent.
//For this example, we simply create an intent that
// will bring us directly back to this activity.
//A more typical implementation would use a
// data Uri in order to display a more specific result,
//or a custom action in order to
// launch a specific operation.
Intent shortcutIntent =
new
Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(
this
,
this
.getClass().getName());
shortcutIntent.putExtra(EXTRA_KEY,
"ApiDemos Provided This Shortcut"
);
// Then, set up the container intent (the response to the caller)
Intent intent =
new
Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_name));
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
this
, R.drawable.app_sample_code);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
// Now, return the result to the launcher
setResult(RESULT_OK, intent);
}
上一篇
获取system系统调用的输出
下一篇
CPU 测速(MHz)和高精度延时(微秒级)
相关文章
1.
Android 添加、移除和判断 桌面快捷方式图标
2.
清除桌面快捷方式小图标的超快方法
3.
Android O添加桌面快捷方式
4.
Android 7.0新特性——桌面长按图标出现快捷方式
5.
桌面快捷方式去角标
6.
安卓桌面快捷方式
7.
Android 8.0 创建桌面快捷方式
8.
android 建立 删除桌面快捷方式
9.
win10桌面快捷方式图标变白的解决方法
10.
Android 添加桌面快捷方式操做
更多相关文章...
•
Eclipse 快捷键
-
Eclipse 教程
•
ionic icon(图标)
-
ionic 教程
•
IntelliJ IDEA 代码格式化配置和快捷键
•
常用的分布式事务解决方案
相关标签/搜索
快捷方式
shortcut
快捷
create
桌面
方方面面
图快
图标
标图
Android
MySQL教程
PHP教程
Redis教程
面试
设计模式
委托模式
0
分享到微博
分享到微信
分享到QQ
每日一句
每一个你不满意的现在,都有一个你没有努力的曾经。
最新文章
1.
.Net core webapi2.1生成exe可执行文件
2.
查看dll信息工具-oleview
3.
c++初学者
4.
VM下载及安装
5.
win10下如何安装.NetFrame框架
6.
WIN10 安装
7.
JAVA的环境配置
8.
idea全局配置maven
9.
vue项目启动
10.
SVN使用-Can't remove directoryXXXX,目录不是空的,项目报错,有红叉
本站公众号
欢迎关注本站公众号,获取更多信息
相关文章
1.
Android 添加、移除和判断 桌面快捷方式图标
2.
清除桌面快捷方式小图标的超快方法
3.
Android O添加桌面快捷方式
4.
Android 7.0新特性——桌面长按图标出现快捷方式
5.
桌面快捷方式去角标
6.
安卓桌面快捷方式
7.
Android 8.0 创建桌面快捷方式
8.
android 建立 删除桌面快捷方式
9.
win10桌面快捷方式图标变白的解决方法
10.
Android 添加桌面快捷方式操做
>>更多相关文章<<