帅哥美女们速度进来看看啊

码密码密哄 2011-07-21 06:54:12
大家帮忙看看,怎么判断不了到底有没创建快捷方式啊 ,每次都弹窗口显示是否创建快捷方式 ,怎么回事啊?
谢谢各位帅哥美女们了,I Love U....
无关代码我都打斜线注释了啊 我已经创建了快捷方式的时候 也弹对话框 郁闷死了 拜托大家了


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initService();
setContentView(R.layout.main_tab);

//创建快捷方式
if(isInstallShortcut()==false){
showDialog();
}
// mTabHost = getTabHost();
//driverName = Build.MODEL;
//setupTabsEmpty();
// setupTabs();

//initProgress();
//checkVersion();


}

//弹出是否创建快捷方式对话框
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(getResources().getString(R.string.ma_shorcut_title))
.setMessage(getResources().getString(R.string.ma_addorno_sc))
.setPositiveButton(getResources().getString(R.string.ok), new OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
addShortcut();
}
}).setNegativeButton(getResources().getString(R.string.cancel), null).create().show();
}

//在桌面添加快捷方式
private void addShortcut() {
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);

ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
sendBroadcast(shortcut);
}

//判断是否存在快捷方式
private boolean isInstallShortcut() {
ContentResolver contentResolver = this.getContentResolver();
String authority = "com.android.launcher.settings";
Uri content_uri = Uri.parse("content://" + authority + "/favorites?notify=true");
Cursor cursor = contentResolver.query(content_uri, new String[] {"title", "iconResource"}, "title=?",
new String[]{MainActivity.this.getResources().getString(R.string.app_name)}, null);
if(cursor != null && cursor.getCount() > 0){
return true;
}else{
return false;
}
}
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinqiqi123 2011-07-21
  • 打赏
  • 举报
回复
private void addShortcut() 方法里若添加快捷方式成功应该存一下
private boolean isInstallShortcut() 方法查询出来才不为空,才会返回true
还有这个“/favorites?notify=true“什么意思?
fishmen26 2011-07-21
  • 打赏
  • 举报
回复
你确定你的query 语句 写对了的?

还有cursor 如果不为空,一定要记得关闭啊


if(cursor != null}{
try{
//do something.
}finally{
cursor.close();
}
}}
fishmen26 2011-07-21
  • 打赏
  • 举报
回复
你确定你的query 语句写的没问题?

如果cursor 不为 null。 函数返回的时候一定关闭cursor哦

if(cursor != null){
try{
//do something.
beyondma 2011-07-21
  • 打赏
  • 举报
回复
cursor 你创建完之后还是0?

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧