在捷徑的開發中首先要確定是否存在捷徑:一般在程式的歡迎介面及開啟程式的第一個介面的Activity的onCreate方法中添加
if (isInstallShortcut()) {
Toast.makeText(mContext, "已存在捷徑", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(mContext, "無捷徑", Toast.LENGTH_LONG).show();
}
建立方法:
/**
* 判斷是否已有捷徑
*
* @return
*/
private boolean isInstallShortcut() {
// TODO Auto-generated method stub
boolean isInstallShortcut = false;
final ContentResolver cr = mContext.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[] { mContext.getResources().getString(
R.string.app_name) }, null);
if (c != null && c.getCount() > 0) {
isInstallShortcut = true;
}
return isInstallShortcut;
}
www.2cto.com
最後,添加許可權:
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"
OK!判斷完成!
摘自 鳥人如風,不舍晝夜.