在Android中,如果用户要在桌面上创建你的程序的快捷方式,那么需要长按桌面,然后shortcuts,再进入application里面找很久才能找到。那么怎么才能让你的程序出现在shortcut这一层中呢。

首先,在AndroidManifest中定义这样一个Activity

<activity android:name=".CreateShortCut" android:theme="@android:style/Theme.NoDisplay" > <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>

这个CreateShortCut本身是这样写的

package com.locatify.tourguide; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; public class CreateShortCut extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER); shortcutIntent.setClassName(this, MainActivity.class.getName()); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); Parcelable iconResource = Intent.ShortcutIconResource.fromContext( this, R.drawable.icon); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); // Now, return the result to the launcher setResult(RESULT_OK, intent); finish(); } }

更多相关文章

  1. Android提高篇之自定义dialog实现processDialog“正在加载”效果
  2. android 自定义地图初步实现
  3. Android系统架构和四大组件
  4. Android学习笔记一:Android开发环境搭建和第一个应用程序
  5. Cygwin环境下使用Android(安卓)NDK r9c编译boost 1.55
  6. android JNI 系列 一
  7. 一个简单的Android程序的登录界面
  8. Android(安卓)软件安装程序(*.apk)的结构分析、反编译以及汉化
  9. Android高手秘笈之自定义View的属性

随机推荐

  1. Android中如何提高UI的性能
  2. Android实现加载网页,获取网页上图以及点
  3. web app和本地app之争 及其 iOS和Android
  4. Android中的基类—抽取出来公共的方法
  5. android环信昵称头像解决方法
  6. Android投屏(屏幕共享)设计需要考虑的关键
  7. Android获取本地图片缩略图终极解决方案
  8. 电脑怎么安装安卓(Android)x86 不使用U盘
  9. android指定签名的apk才能安装
  10. 使用android studio环境新建一个工程——