Android向Launcher添加快捷方式 Android实现向Launcher添加快捷方式的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Android向Launcher添加快捷方式 Android实现向Launcher添加快捷方式的方法

Ruthless   2021-03-20 我要评论
想了解Android实现向Launcher添加快捷方式的方法的相关内容吗,Ruthless在本文为您仔细讲解Android向Launcher添加快捷方式的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,Launcher,添加,快捷方式,下面大家一起来学习吧。

本文实例讲述了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>

运行结果:

希望本文所述对大家的Android程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们