Android添加快捷方式(Short)到手机桌面

本文详细介绍了在Android应用中如何添加和移除桌面快捷方式,包括权限设置、添加快捷方式的广播实现、移除快捷方式的action及查询快捷方式的方法,同时提及了在不同手机上的测试结果。
摘要由CSDN通过智能技术生成

一、在日常开发中,我们经常会遇到这样的需求就是网桌面添加快捷方式:常见的快捷方式有两种:一是APP的快捷方式,一是widget插件的快捷方式。下面详细介绍这两种情况的应用:

   参考网站:http://www.cnblogs.com/lhxin/archive/2012/05/30/2526525.html

                      http://blog.csdn.net/xubin341719/article/details/7059285

二、APP的快捷方式:

      1、 app快捷方式的实现又有两种情况,一是直接在桌面生成;一是通过长按桌面,在弹出的快捷菜单中生成。

      2、直接生成快捷方式主要是通过发送系统广播InstallShortcutReceiver实现的。

           我们先来看一下InstallShortcutReceiver的源代码。位于packages\apps\Launcher2\src\com\android\launcher2下面:

          

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. /* 
  2.  * Copyright (C) 2008 The Android Open Source Project 
  3.  * 
  4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  * you may not use this file except in compliance with the License. 
  6.  * You may obtain a copy of the License at 
  7.  * 
  8.  *      http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  * Unless required by applicable law or agreed to in writing, software 
  11.  * distributed under the License is distributed on an "AS IS" BASIS, 
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  * See the License for the specific language governing permissions and 
  14.  * limitations under the License. 
  15.  */  
  16.   
  17. package com.android.launcher2;  
  18.   
  19. import java.util.ArrayList;  
  20.   
  21. import android.content.BroadcastReceiver;  
  22. import android.content.Context;  
  23. import android.content.Intent;  
  24. import android.widget.Toast;  
  25.   
  26. import com.android.launcher.R;  
  27.   
  28. public class InstallShortcutReceiver extends BroadcastReceiver {  
  29.     public static final String ACTION_INSTALL_SHORTCUT =  
  30.             "com.android.launcher.action.INSTALL_SHORTCUT";  
  31.   
  32.     // A mime-type representing shortcut data  
  33.     public 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值