在android应用启动时中我写了个判断快捷方式的方法,但是它总是返回false,并不会返回true,请问下我哪里写错了吗?
谢谢各位了!
代码如下: private boolean isFavorites() {
boolean isInstallShortcut = false;
final ContentResolver cr = getContentResolver();
final String AUTHORITY = "com.android.launcher.settings";
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI,new String[] { "title", "iconResource" }, "title=?",new String[] { getString(R.string.app_name) }, null);
if (c != null && c.getCount() > 0)
isInstallShortcut = true;
return isInstallShortcut;
}
谢谢各位了!
代码如下: private boolean isFavorites() {
boolean isInstallShortcut = false;
final ContentResolver cr = getContentResolver();
final String AUTHORITY = "com.android.launcher.settings";
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI,new String[] { "title", "iconResource" }, "title=?",new String[] { getString(R.string.app_name) }, null);
if (c != null && c.getCount() > 0)
isInstallShortcut = true;
return isInstallShortcut;
}
解决方案 »
- 检查一下你的编程语言基础知识怎么样,说出这段代码输出结果,为什么?
- 配置文件出错?Unknown C compiler arm-linux-androideabi-gcc ?
- @TestTargets是什么 JAVA单元测试的问题,JUNIT,等你不关机
- 求问有没有哪位大侠有类似于我查查软件的源代码?是基于android平台的。
- Android中备忘录
- 请高手帮忙,android 同步问题, 在我的contact sync的时候
- 如何向values文件夹下添加一个新的xml配置文件
- 从服务器端获取JSON格式的数据进行解析的问题,求帮助
- Android WebView开发问题及优化汇总
- 怎么把这个表白程序变成apk
- 请教android中binder的问题
- android 双卡双待手机 发送短信选择卡1还是卡2发送的问题
这个名称你改改,手动写,不行就试试packagename
我是想先判断有没有这个快捷方式存在,如果存在就不创建,不存在则创建。
虽然我是用的中文,但是android系统它为什么能创建并提示出来呢?其实我就想把android系统创建快捷方式的时候那个提示给去掉,请问有什么办法吗?再次谢谢了!
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
shortcut.putExtra("duplicate", false); // 不允许重复创建 // 指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
// 注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
ComponentName comp = new ComponentName(this.getPackageName(), "."
+ this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
Intent.ACTION_MAIN).setComponent(comp)); // 快捷方式的图标
Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource
.fromContext(this, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
}
改成
final String AUTHORITY ="com.android.launcher2.settings";试试