2011.09.15 ——— android 桌面添加快捷方式之判断是否存在无效
参考:
http://maxuefeng.blog.51cto.com/1876326/528645
http://blog.163.com/ethan_518/blog/static/177959139201161934629363/
前面写了如何创建 删除和判断快捷方式的方法 但是后来发现判断快捷方式的方法不是总是很有效 上网查了下 发现大家的为问题都是2.2版本之后的就判断不正确了
在此 将原来的判断方法贴一下
private boolean hasShortCut() {
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(Uri.parse("content://com.android.launcher.settings/favorites?notify=true"), null, "title=?",
new String[] {getString(R.string.app_name)}, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.close();
return true;
}
return false;
}
后来 我看了一下2.2版本和1.5版本的launcher中的清单文件
1.5的如下:
<!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name=".InstallShortcutReceiver"
android:permission="com.lp.launcher.permission.INSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.lp.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- Intent received used to uninstall shortcuts from other applications -->
<receiver
android:name=".UninstallShortcutReceiver"
android:permission="com.lp.launcher.permission.UNINSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.lp.launcher.action.UNINSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- The settings provider contains Home's data, like the workspace favorites -->
<provider
android:name="LauncherProvider"
android:authorities="com.lp.launcher.settings"
android:writePermission="com.lp.launcher.permission.WRITE_SETTINGS"
android:readPermission="com.lp.launcher.permission.READ_SETTINGS" />
2.2的如下:
<!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name="com.android.launcher2.InstallShortcutReceiver"
android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- Intent received used to uninstall shortcuts from other applications -->
<receiver
android:name="com.android.launcher2.UninstallShortcutReceiver"
android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- The settings provider contains Home's data, like the workspace favorites -->
<provider
android:name="com.android.launcher2.LauncherProvider"
android:authorities="com.android.launcher2.settings"
android:writePermission="com.android.launcher.permission.WRITE_SETTINGS"
android:readPermission="com.android.launcher.permission.READ_SETTINGS" />
可以看出来 创建和删除快捷方式的receiver没什么变化
但是查询的provider有了变化
android:authorities="com.android.launcher.settings"
android:authorities="com.android.launcher2.settings"
所以说我们的方法用在2.2之后的版本是无效的
现修改代码如下:
public static boolean hasShortCut(Context context) {
String url = "";
System.out.println(getSystemVersion());
if(getSystemVersion() < 8){
url = "content://com.android.launcher.settings/favorites?notify=true";
}else{
url = "content://com.android.launcher2.settings/favorites?notify=true";
}
ContentResolver resolver = context.getContentResolver();
Cursor cursor = resolver.query(Uri.parse(url), null, "title=?",
new String[] {context.getString(R.string.app_name)}, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.close();
return true;
}
return false;
}
private static int getSystemVersion(){
return android.os.Build.VERSION.SDK_INT;
}
分享到:
相关推荐
这篇博客“2011.10.13(2)——— android Matrix学习03”可能深入探讨了Matrix类的一些高级用法和实践技巧。虽然描述中没有提供具体信息,但从标题可以推断,这可能是系列教程的第三部分,继续深化对Matrix的理解。...
基于因子分析的我国A股上市...争力评价——以医药企业为例_张澳.caj
微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+...
python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目...
微信小程序——万年历(截图+源码).zip 微信小程序——万年历(截图+源码).zip 微信小程序——万年历(截图+源码).zip 微信小程序——万年历(截图+源码).zip 微信小程序——万年历(截图+源码).zip 微信小程序...
python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ...
微信小程序——卡卡汽车 获取用户 设备信息(截图+源码).zip 微信小程序——卡卡汽车 获取用户 设备信息(截图+源码).zip 微信小程序——卡卡汽车 获取用户 设备信息(截图+源码).zip 微信小程序——卡卡汽车 ...
在Android操作系统中,桌面快捷方式是一种便捷的方式,允许用户快速访问他们经常使用的应用程序、联系人、设置或者其他功能。本文将详细讲解如何创建和删除Android桌面快捷方式,以及它们的工作原理。 **一、创建...
java毕业设计——百货中心供应链管理系统(论文+源代码+数据库+讲解视频).zip java毕业设计——百货中心供应链管理系统(论文+源代码+数据库+讲解视频).zip java毕业设计——百货中心供应链管理系统(论文+源代码+...
1,安装说明.txt ——————————安装手册 2,jdk-170.tar.gz ——————————JDK1.7deb包 3,switch_java.sh -------------------------java其它版本切换 4,check_java.sh———————————版本...
Android support.v7包
Geomagic.Studio.2012软件,由于太大,分成八个压缩包以及一个其他文件包。 此文件为part5
Android中文翻译组——Android中文API合集(4).chm
在Android系统中,APK是应用程序的安装包,它包含了所有必要的代码、资源和配置文件。为了让用户能够从非Google Play商店来源安装APK,并确保其安全性和完整性,开发者需要对APK进行签名。签名过程涉及到一系列的...
15. 罗锅过马路 ———— 不死也直(值)了!形容幸运降临,即使付出生命也值得。 16. 六指儿抓痒 ———— 多一道子!形容额外的努力或不必要的干预。 17. 长胡子尿炕 ———— 老毛病!指出某些持久不变的缺点或...
1. 显示快捷方式的权限提示:在Android 8.0(API级别26)及以上版本,首次创建动态快捷方式时,系统会提示用户是否允许添加。确保在创建快捷方式前检查`ShortcutManager`的`isRequestPinShortcutSupported()`方法,...
matlab课程设计——调幅广播系统的仿真设计 完整版.docxmatlab课程设计——调幅广播系统的仿真设计 完整版.docxmatlab课程设计——调幅广播系统的仿真设计 完整版.docxmatlab课程设计——调幅广播系统的仿真设计 ...
在Android应用开发中,APK文件是应用程序的打包格式,其中包含了所有必要的资源和代码。为了确保APK的安全性和完整性,Android系统使用签名机制。在APK中,MANIFEST.MF、CERT.SF和CERT.RSA这三个文件是签名过程的...
录音软件MP3——Cooolsoft MP3 Sound Recorder2.88汉化版.exe录音软件MP3——Cooolsoft MP3 Sound Recorder2.88汉化版.exe录音软件MP3——Cooolsoft MP3 Sound Recorder2.88汉化版.exe录音软件MP3——Cooolsoft MP3 ...