如何创建快捷方式

来源:互联网 发布:淘宝仿包 编辑:程序博客网 时间:2024/05/18 00:10
package cn.itcast.shortcut;




import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;


public class CreateshortcutActivity extends Activity {
    /** Called when the activity is first created. */
    private static final String EXTRA_KEY = "cn.itcast.shortcut.CreateshortcutActivity";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    public void click(View view){
    Intent intent = new Intent();
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    /**
     *  An Intent representing the shortcut. 
     *  The intent must contain three extras: 
     *  SHORTCUT_INTENT (value: Intent), 
     *  SHORTCUT_NAME (value: String), and 
     *  SHORTCUT_ICON (value: Bitmap) or 
     *  SHORTCUT_ICON_RESOURCE (value: ShortcutIconResource).


     */
    Intent callintent = new Intent();
    callintent.setAction(Intent.ACTION_CALL);
    callintent.setData(Uri.parse("tel:123456"));
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, callintent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HAH");
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.ic_launcher);
        sendBroadcast(intent);
    }
}
原创粉丝点击