标签:android style blog http color os io java strong
[java] view plaincopy
import java.util.List;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
public class LauncherUtils {
public static void readLauncherDB(Context context) {
final ContentResolver cr = context.getContentResolver();
String AUTHORITY = getAuthorityFromPermission(context,
"com.android.launcher.permission.READ_SETTINGS");
if (AUTHORITY == null) {
AUTHORITY = getAuthorityFromPermission(context,
"com.android.launcher.permission.WRITE_SETTINGS");
}
if (AUTHORITY == null) {
Log.e("", "no authority");
return;
}
Log.e("", "authority:" + AUTHORITY);
Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/favorites?notify=true");
Cursor c = cr.query(CONTENT_URI, null, null, null, null);
if (c != null) {
while (c.moveToNext()) {
int id = c.getInt(c.getColumnIndex("_id"));
// 快捷方式的名称
String title = c.getString(c.getColumnIndex("title"));
// 快捷方式启动的对象
String intent = c.getString(c.getColumnIndex("intent"));
int container = c.getInt(c.getColumnIndex("container"));
// 快捷方式在哪个屏幕,默认是1
int screen = c.getInt(c.getColumnIndex("screen"));
// 快捷方式的位置
int cellX = c.getInt(c.getColumnIndex("cellX"));
int cellY = c.getInt(c.getColumnIndex("cellY"));
int spanX = c.getInt(c.getColumnIndex("spanX"));
int spanY = c.getInt(c.getColumnIndex("spanY"));
int itemType = c.getInt(c.getColumnIndex("itemType"));
int appWidgetId = c.getInt(c.getColumnIndex("appWidgetId"));
int isShortcut = c.getInt(c.getColumnIndex("isShortcut"));
int iconType = c.getInt(c.getColumnIndex("iconType"));
// 快捷方式的图标
String iconPackage = c.getString(c
.getColumnIndex("iconPackage"));
// "iconResource"
// "icon"
// "uri"
// "displayMode"
int launchCount = c.getInt(c.getColumnIndex("launchCount"));
// "sortMode"
int itemFlags = c.getInt(c.getColumnIndex("itemFlags"));
String log = "id=" + id + "|title=" + title + "|intent="
+ intent + "|container=" + container + "|screen="
+ screen + "|cell=[" + cellX + "," + cellY + "]|"
+ "span=[" + spanX + "," + spanY + "]|itemType="
+ itemType + "|appWidgetId=" + appWidgetId
+ "|isShortcut=" + isShortcut + "|iconType=" + iconType
+ "|iconPackage=" + iconPackage + "|launchCount="
+ launchCount + "|itemFlags=" + itemFlags;
Log.e("", log);
}
}
}
/**
* 获取authority
* @param context
* @param permission
* @return
*/
static String getAuthorityFromPermission(Context context, String permission) {
if (permission == null)
return null;
List<PackageInfo> packs = context.getPackageManager()
.getInstalledPackages(PackageManager.GET_PROVIDERS);
if (packs != null) {
for (PackageInfo pack : packs) {
ProviderInfo[] providers = pack.providers;
if (providers != null) {
for (ProviderInfo provider : providers) {
if (permission.equals(provider.readPermission))
return provider.authority;
if (permission.equals(provider.writePermission))
return provider.authority;
}
}
}
}
return null;
}
}
标签:android style blog http color os io java strong
原文地址:http://my.oschina.net/u/1777508/blog/308483