Android 创建快捷方式

本文介绍了如何在Android应用中创建快捷方式,包括所需代码、关键步骤和实例演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

在你的项目清单中看到如下代码代表这个activity是本应用的启动activity。系统会自动为创建快捷方式。在你使用一些应用时它有时会让你创建快捷方式 比如 UC浏览器.这是怎么做的呢?其实也很简单。只需:
/**
* 这两行代码说明你想干嘛
*/
Uri uri = Uri.parse("tel:0800000123");
Intent myIntent = new Intent(Intent.ACTION_DIAL, uri);

Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

Parcelable icon = Intent.ShortcutIconResource.
fromContext(this,R.drawable.beach); // 获取快捷键的图标
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式的图标

//shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, R.drawable.beach); //可以代替上面两行代码
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");// 快捷方式的标题
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 快捷方式的动作

sendBroadcast(shortcut);// 完了你还可以告诉系统你创建了个快捷方式


如果你还想在创建快捷方式栏中添加一个你自己的条目 比如
[img]http://dl.iteye.com/upload/picture/pic/97871/f21e2f58-497a-370b-85e3-3ee07033672c.png[/img]
[img]http://dl.iteye.com/upload/picture/pic/97873/649b8e51-7f67-38e6-9bdf-896be702e867.png[/img]

你也只需在清单文件中加入:(你要创建一个activity哦 NoneShortcut)
<activity android:name=".NoneShortcut" android:icon="@drawable/photo6" android:label="哈哈">
<intent-filter >
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
</intent-filter>
</activity>



Intent用法汇总详见:[url]http://sunney2012.iteye.com/blog/1162227[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值