给一个完整的代码片段:
然后我们需要在配置文件中进行如下设置:
/**Launcher的receiver标签的intent-filter的一个action过滤条件*/
private final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
private String numToDial = null;
private Parcelable icon = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
/** 桌面快捷方式图标资源ID */
icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
/** 快捷方式的名称 */
numToDial = "110";
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, numToDial);
/** 启动目标组件的Intent */
Intent directCall = new Intent();
directCall.setData(Uri.parse("tel:" + numToDial));
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, directCall);
sendBroadcast(addShortcut);
}
然后我们需要在配置文件中进行如下设置:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.edison.shor" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
.......
</application>
</manifest>