Android创建ShortCut
在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(); } }
更多相关文章
- Android提高篇之自定义dialog实现processDialog“正在加载”效果
- android 自定义地图初步实现
- Android系统架构和四大组件
- Android学习笔记一:Android开发环境搭建和第一个应用程序
- Cygwin环境下使用Android(安卓)NDK r9c编译boost 1.55
- android JNI 系列 一
- 一个简单的Android程序的登录界面
- Android(安卓)软件安装程序(*.apk)的结构分析、反编译以及汉化
- Android高手秘笈之自定义View的属性