标签:
<!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name="com.android.launcher2.InstallShortcutReceiver"
android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- Intent received used to uninstall shortcuts from other applications -->
<receiver
android:name="com.android.launcher2.UninstallShortcutReceiver"
android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />
</intent-filter>
</receiver>
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void createShortcut(View view){
//1.调用系统的提供的创建快捷方式的功能
Intent intent = new Intent();
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
//2.给快捷方式设置名称
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "女神求救神器");
//3.给快捷方式设置图标
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.safe));
//4.设置快捷方式的功能
Intent c = new Intent();
c.setAction(Intent.ACTION_CALL);
c.setData(Uri.parse("tel:110"));
//添加快捷方式功能的意图
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, c);
//5.调用系统提供的创建快捷方式的意图
sendBroadcast(intent);
}
}
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
标签:
原文地址:http://www.cnblogs.com/candledragle/p/4260971.html