大家帮忙看看,怎么判断不了到底有没创建快捷方式啊 ,每次都弹窗口显示是否创建快捷方式 ,怎么回事啊?
谢谢各位帅哥美女们了,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;
}
}
谢谢各位帅哥美女们了,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;
}
}
解决方案 »
- adb连接一定要root吗?
- 关于WebView的手势监听问题
- 修改代码后,无法启动
- android 使用Google Calendar API 更新日历问题 100分求助!!!!!!
- 电子书应用开发
- 问个弱弱的问题:什么时候用this?什么时候用<当前类名>.this?
- 求助Android问题
- android的Wifi Direct功能
- Android mp4文件frame获取
- android webservice返回的内容为string怎么转换成listview里
- android网络相册软件,连接网址,并浏览网站上的相册,请问如何操作
- 对"singleTask"有点不太理解,求帮助。。。刚看了Tasks and Back Stack
try{
//do something.
if(cursor != null}{
try{
//do something.
}finally{
cursor.close();
}
}}
private boolean isInstallShortcut() 方法查询出来才不为空,才会返回true
还有这个“/favorites?notify=true“什么意思?