快捷方式 java 桌面_创建桌面快捷方式

添加桌面快捷方式,非常简单,只需三步:

1、创建一个添加快捷方式的Intent,该Intent的Action为com.android.launcher.action.INSTALL_SHORTCUT。

2、通过为该Intent添加Extra属性来设置快捷方式的标题、图标及快捷方式对应启动的程序。

3、调用sendBroadcast()方法发送广播即可添加快捷方式。

下面用一个简单示例来演示,在该应用程序中,只给出了添加桌面快捷方式的内容,程序的具体应用无须给出,第一次安装该程序后,会在桌面创建快捷方式,以后不会再创建快捷方式。代码如下:

Activity:

package com.home.activity;

import com.example.testshortcut.R;

import android.app.Activity;

import android.content.Intent;

import android.content.SharedPreferences;

import android.content.SharedPreferences.Editor;

import android.os.Bundle;

import android.os.Parcelable;

import android.widget.Toast;

public class TestShortcutActivity extends Activity {

private SharedPreferences sp;

private Editor editor;

private int count = 1

你可能感兴趣的:(快捷方式,java,桌面)