设为首页 加入收藏

TOP

手机APP创建桌面快捷方式
2017-10-12 18:11:34 】 浏览:10020
Tags:手机 APP 创建 桌面 快捷 方式

 

 

预览:

 

需要权限:

   1 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 

 

配置文件:AndroidManifest.xml

1  <activity
2             android:name="com.myself.news.activity.GuideActivity"
3             android:label="@string/title_activity_guide" >
4             <intent-filter>
5                 <action android:name="com.myself.news.ACTION_HOME" />
6 
7                 <category android:name="android.intent.category.DEFAULT" />
8             </intent-filter>
9         </activity>

 

在应用的闪屏页面Activity的 oncreate方法调用 installShortcut();

代码:

 1 // 创建快捷方式
 2     // com.android.launcher.permission.INSTALL_SHORTCUT
 3     private void installShortcut() {
 4         // 判断有没有创建过快捷方式
 5         boolean isCreated = SharedPreferencesUtils.getBoolean(this,
 6                 GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, false);
 7         // 判断是否已经创建过
 8         if (!isCreated) {
 9             // 发广播
10             Intent intent = new Intent();
11             intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
12 
13             // 图标
14             // 根据资源文件id生成Bitmap对象
15             intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory
16                     .decodeResource(getResources(), R.drawable.ic_launcher));
17             // 名称
18             intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手机安全卫士");
19 
20             // 动作
21             Intent actionIntent = new Intent();
22             // 跳到主页面
23             actionIntent.setAction(GlobalConstantsUtils.ACTION_HOME);
24 
25             intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
26             sendBroadcast(intent);
27 
28             // 标记已经创建过快捷方式,下次不再创建
29             SharedPreferencesUtils.setBoolean(this,
30                     GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, true);
31         }
32     }

 

常量工具类GlobalConstantsUtils:

 

 1 public static final String PREF_IS_SHORTCUT_INTALLED = "is_shortcut_intalled";// 是否已经创建快捷方式 

 1 public static final String ACTION_HOME = "com.myself.news.ACTION_HOME";// 跳转到主页面的ACTION 

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Fragment 与Activity 下一篇安卓开发树形控件之ExpandableLis..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目