当前位置: 代码迷 >> Android >> android 创造桌面快捷方式
  详细解决方案

android 创造桌面快捷方式

热度:83   发布时间:2016-05-01 19:20:32.0
android 创建桌面快捷方式

public class Activity01 extends Activity
{
??????? public void onCreate(Bundle savedInstanceState)
??????? {
??????????????? super.onCreate(savedInstanceState);
??????????????? setContentView(R.layout.main);
??????????????? //要添加的快捷方式的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:[email protected]" ));
??????????????????????? //添加快捷方式Intent
??????????????????????? addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mailto);?
??????????????????????? //正常
??????????????????????? setResult(RESULT_OK,addShortcut);?
??????????????? }
??????????????? else
??????????????? {
??????????????????????? //取消
??????????????????????? setResult(RESULT_CANCELED);?
??????????????? }
??????????????? //关闭
??????????????? finish();?
??????? }
}

  相关解决方案