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); //
                }
            });
  • 相关阅读:
    ffmpeg参数说明
    【FFmpeg】FFmpeg常用基本命令
    ffmpeg最全的命令参数
    数据库总结
    linux redis安装及JAVA使用jedis
    记录一次工作中jvm被linux杀死的调查
    ExecutorService线程池submit的使用
    java四种引用与回调函数
    java排序
    NIO教程笔记
  • 原文地址:https://www.cnblogs.com/AndyGe/p/3442590.html
Copyright © 2011-2022 走看看