手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android实现向Launcher添加快捷方式的方法
Android实现向Launcher添加快捷方式的方法
摘要:本文实例讲述了Android实现向Launcher添加快捷方式的方法。分享给大家供大家参考。具体如下:当我们在应用程序Launcher的桌面...

本文实例讲述了Android实现向Launcher添加快捷方式的方法。分享给大家供大家参考。具体如下:

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

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

选择快捷方式后,会弹出一个对话框,显示出了可添加快捷方式的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); } }

清单文件:

<"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实现向Launcher添加快捷方式的方法2

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

【Android实现向Launcher添加快捷方式的方法】相关文章:

Android 设置应用全屏的两种解决方法

android之计时器(Chronometer)的使用以及常用的方法

Android实现图片循环播放的实例方法

Android启动模拟器报错解决方法

Android中button实现onclicklistener事件的两种方式

Android开发之动画实现方法

android中添加按钮事件的方法

Android实现多线程断点下载的方法

android中处理各种触摸事件的方法浅谈

android获取监听SD Card状态的方法

精品推荐
分类导航