帅哥美女们速度进来看看啊
码密码密哄 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;
}
}