編輯:關於Android編程
寫了個小Demo,實現了設置壁紙和創建桌面圖標的邏輯:
創建壁紙比較簡單,將Drawable轉為Bitmap,然後直接用setWallpaper就行了:
Bitmap bitmap = BitmapFactory.decodeResource(Main.this.getResources(), R.drawable.wallpaper);
try {
Main.this.setWallpaper(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
if (!hasShortcut()) {
addShortcut();
} else {
Toast.makeText(Main.this, 桌面圖標已存在, Toast.LENGTH_SHORT).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); //不允許重復創建
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this, this.getClass().getName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
//圖標
Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
}
/**
* 刪除應用的桌面圖標
*/
private void delShortcut() {
Intent shortcut = new Intent(com.android.launcher.action.UNINSTALL_SHORTCUT);
//圖標名稱
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
String appClass = this.getPackageName() + . + this.getLocalClassName();
ComponentName comp = new ComponentName(this.getPackageName(), appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
sendBroadcast(shortcut);
}
判斷桌面圖標是否已經存在:
private boolean hasShortcut() {
boolean isInstallShortcut = false;
final ContentResolver cr = Main.this.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[]{Main.this.getString(R.string.app_name).trim()}, null);
if (c != null && c.getCount() > 0) {
isInstallShortcut = true;
}
return isInstallShortcut;
}
56.EasyLikeArea
EasyLikeArea Easy like area in the circle of friends or QQ qzone
Android開發之使用HTTP訪問網絡資源
使用HTTP訪問網絡資源 前面介紹了 URLConnection己經可以非常方便地與指定站點交換信息,URLConnection還有一個子類:HttpURL
Android開發之友盟統計
當我們開發好App後就會把它發到應用市場上,但是目前有很的應用市場(如,豌豆莢,應用寶,安卓市場等)那麼問題來了,假如我們想統計我們開發的應用的下載次數,就必須把各個應用
RecyclerView使用完全指南,是時候體驗新控件了(一)
1. 概述官方介紹,RecyclerView用於在有限的窗口展現大量的數據,其實早已經有了類似的控件,如ListView、GridView,那麼相比它們,Recycler