基本信息
源码名称:android 创建/删除快捷方式 示例源码下载
源码大小:0.04M
文件格式:.rar
开发语言:Java
更新时间:2014-03-25
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.ldj.shortcuts; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Parcelable; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class Shortcuts extends Activity { private Button btnCallShortcut,btnSelfShortcut,btnDeleteCall,btnDeleteSelf; private static final String SHORTCUT_INSTALL = "com.android.launcher.action.INSTALL_SHORTCUT"; private static final String SHORTCUT_UNINSTALL = "com.android.launcher.action.UNINSTALL_SHORTCUT"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findView(); setListener(); } private void findView() { btnCallShortcut = (Button)findViewById(R.id.btn_callshortcut); btnSelfShortcut = (Button)findViewById(R.id.btn_selfshortcut); btnDeleteCall = (Button)findViewById(R.id.btn_deletecall); btnDeleteSelf = (Button)findViewById(R.id.btn_deletself); } private void setListener() { btnCallShortcut.setId(0); btnCallShortcut.setOnClickListener(new ShortcutBtnListenter()); btnSelfShortcut.setId(1); btnSelfShortcut.setOnClickListener(new ShortcutBtnListenter()); btnDeleteCall.setId(2); btnDeleteCall.setOnClickListener(new ShortcutBtnListenter()); btnDeleteSelf.setId(3); btnDeleteSelf.setOnClickListener(new ShortcutBtnListenter()); } /* * 生成打电话快捷方式 */ private void addCallShortcut() { Intent shortcut = new Intent(SHORTCUT_INSTALL); //显示的名字 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Call"); //显示的图标 Parcelable icon = Intent.ShortcutIconResource.fromContext(this,android.R.drawable.ic_menu_call); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); //不允许重复创建 shortcut.putExtra("duplicate",false); /* * 这个Intent是快捷方式所实现的功能 * 这里实现的是打10010电话的功能 */ Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel://10010")); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); //发送广播用以创建shortcut this.sendBroadcast(shortcut); Toast.makeText(this, "创建打电话快捷方式成功", Toast.LENGTH_SHORT).show(); finish(); } /* * 生成自身程序的快捷方式 */ private void addSelfShortcut() { Intent shortcut = new Intent(SHORTCUT_INSTALL); //显示的名字 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Self"); //显示的图标 Parcelable icon = Intent.ShortcutIconResource.fromContext(this,R.drawable.icon); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); //不允许重复创建 shortcut.putExtra("duplicate",false); //这个是快捷方式所实现的功能 Intent intent = new Intent(this,Shortcuts.class); intent.setAction("com.ldj.shortcuts.self"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); //发送广播用以创建shortcut this.sendBroadcast(shortcut); Toast.makeText(this, "创建自身快捷方式成功", Toast.LENGTH_SHORT).show(); finish(); } /* * 删除打电话快捷方式 */ private void deleteCallShortcut() { Intent shortcut = new Intent(SHORTCUT_UNINSTALL); //名字要和创建时的一样 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Call"); //这里的intent要和创建时的intent设置一致 Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel://10010")); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); //发送广播以删除shortcut this.sendBroadcast(shortcut); Toast.makeText(this, "删除打电话快捷方式成功", Toast.LENGTH_SHORT).show(); finish(); } /* * 删除自身程序快捷方式 */ private void deleteSelfShortcut() { Intent shortcut = new Intent(SHORTCUT_UNINSTALL); //显示的名字 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Self"); //这里的intent要和创建时的intent设置一致 Intent intent = new Intent(this,this.getClass()); intent.setAction("com.ldj.shortcuts.self"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); //发送广播以删除shortcut this.sendBroadcast(shortcut); Toast.makeText(this, "删除自身快捷方式成功", Toast.LENGTH_SHORT).show(); finish(); } //Button事件处理 class ShortcutBtnListenter implements OnClickListener { @Override public void onClick(View v) { // TODO 根据不同的按钮调用不同方法 switch(v.getId()) { case 0: addCallShortcut(); break; case 1: addSelfShortcut(); break; case 2: deleteCallShortcut(); break; case 3: deleteSelfShortcut(); break; } } } }