zoukankan      html  css  js  c++  java
  • Android添加桌面快捷方式的简单实现

    核心代码如下:

    Button bn = (Button) findViewById(R.id.bn);
            // 为按钮的单击事件添加监听器
            bn.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View source) {
                    // 创建添加快捷方式的Intent
                    Intent addIntent = new Intent(
                            "com.android.launcher.action.INSTALL_SHORTCUT"); //
                    String title = getResources().getString(R.string.title);
                    // 设置快捷方式的标题
                      addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); //// 加载快捷方式的图标
                      Parcelable icon = Intent.ShortcutIconResource.fromContext(
                            AddShortcut.this, R.drawable.ic_launcher);
                    // 设置快捷方式的图标
                      addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); //// 创建点击快捷方式后操作Intent,该处当点击创建的快捷方式后,再次启动该程序
                      Intent myIntent = new Intent(AddShortcut.this,
                            AddShortcut.class);
                    // 设置快捷方式对应的Intent
                    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent); //// 发送广播添加快捷方式
                    sendBroadcast(addIntent); //
                }
            });
  • 相关阅读:
    python中类中的@property
    Python列表的三种遍历(序号和值)的方法
    Numpy一文全了解
    python中list操作方法
    Material Design
    android动画xml
    java配置opencv-在eclipse中
    android 重装sdk或者系统的时模拟器出现can open ****
    hdu acm 1005
    hdu acm 1007
  • 原文地址:https://www.cnblogs.com/AndyGe/p/3442590.html
Copyright © 2011-2022 走看看