您的位置:首页 > 其它

添加桌面快捷方式

2011-03-21 01:54 253 查看
1:java代码:

// 要添加的快捷方式的Intent

Intent addShortcut;

// 判断是否要添加快捷方式

if (getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) {

addShortcut = new Intent();

// 设置快捷方式的名字

addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "发送邮件");

// 构建快捷方式中专门的图标

Parcelable icon = Intent.ShortcutIconResource.fromContext(this,

R.drawable.mail_edit);

// 添加快捷方式图标

addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

// 构建快捷方式执行的Intent

Intent mailto = new Intent(Intent.ACTION_SENDTO,

Uri.parse("mailto:xxx@xxx.com"));

// 添加快捷方式Intent

addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mailto);

// 正常

setResult(RESULT_OK, addShortcut);

} else {

// 取消

setResult(RESULT_CANCELED);

}

// 关闭

finish();

2:在AndroidManifest.xml里的内容为:

<activity android:name=".Activity01" android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

<action android:name="android.intent.action.CREATE_SHORTCUT" />

</intent-filter>

</activity>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: