当前位置:操作系统 > 安卓/Android >>

Android创建快捷方式

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

在你的项目清单中看到如下代码代表这个activity是本应用的启动activity。系统会自动为创建快捷方式。在你使用一些应用时它有时会让你创建快捷方式 比如 UC浏览器.这是怎么做的呢?其实也很简单。只需:
Java代码 
/**
  * 这两行代码说明你想干嘛
  */ 
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);// 完了你还可以告诉系统你创建了个快捷方式 


如果你还想在创建快捷方式栏中添加一个你自己的条目 比如


 
 

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

本文出自“sunney2012”
 

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,