zoukankan      html  css  js  c++  java
  • Android之快捷方式二——向Launcher添加快捷方式

    当我们在应用程序Launcher的桌面空白处长按触摸时,会出现一个对话框,提示选择要添加的桌面组件,如下图所示

    选择快捷方式后,会弹出一个对话框,显示出了可添加快捷方式的Activity所属的应用程序的图标和名称的列表。当我们想把添加快捷方式的Activity添加到这一列表时,只需要在这个Activity注册时添加一个Action为android.intent.action.CREATE_SHORTCUT的IntentFilter就可以了。

    ShortCutAction类

    package com.ljq.action;

    import android.app.Activity;
    import android.os.Bundle;

    /**
    * 向Launcher添加快捷方式
    *
    *
    @author jiqinlin
    *
    */
    public class ShortCutAction extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }

    }

    清单文件

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ljq.action" android:versionCode="1"
    android:versionName
    ="1.0">
    <application android:icon="@drawable/icon"
    android:label
    ="@string/app_name">
    <activity android:name=".ShortCutAction"
    android:label
    ="@string/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category
    android:name
    ="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
    <action
    android:name
    ="android.intent.action.CREATE_SHORTCUT" />
    </intent-filter>
    </activity>

    </application>
    <uses-sdk android:minSdkVersion="7" />
    </manifest>

    运行结果

  • 相关阅读:
    Windows共享上网的做法
    如何花更少的时间学习更多的知识
    因权限引起的svn提交失败的错误及其解决办法
    ArcGIS二次开发入门(一)
    GeoTiff如何存储颜色表的研究
    html5文件夹上传源码
    vue文件夹上传源码
    前端文件夹上传源码
    asp.net文件夹上传源码
    使用webuploader实现大文件上传分片上传
  • 原文地址:https://www.cnblogs.com/linjiqin/p/1967424.html
Copyright © 2011-2022 走看看