(8) Launcher3 customized ContentProvider content provider, which allows other applications to modify Database updates and perform other operations. launcher3
First, add two permissions.
<Uses-permission android: name = "com. android. launcher3.permission. READ_SETTINGS"/>
<Uses-permission android: name = "com. android. launcher3.permission. WRITE_SETTINGS"/>
These two are the permissions to modify the desktop database.
It cannot be modified without being added.
Get data directly through the content provider,
static ArrayList<ShortcutInfo> getItemsInLocalCoordinates(Context context) { ArrayList<ShortcutInfo> items = new ArrayList<ShortcutInfo>(); final ContentResolver cr = context.getContentResolver(); Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] { LauncherSettings.Favorites.ITEM_TYPE, LauncherSettings.Favorites.CONTAINER, LauncherSettings.Favorites.SCREEN, LauncherSettings.Favorites.CELLX, LauncherSettings.Favorites.CELLY, LauncherSettings.Favorites.SPANX, LauncherSettings.Favorites.SPANY ,LauncherSettings.Favorites.TITLE,LauncherSettings.Favorites.INTENT}, null, null, null); final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE); final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER); final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN); final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX); final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY); final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX); final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY); final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE); final int intenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT); try { while (c.moveToNext()) { ShortcutInfo item = new ShortcutInfo(); item.cellX = c.getInt(cellXIndex); item.cellY = c.getInt(cellYIndex); item.spanX = Math.max(1, c.getInt(spanXIndex)); item.spanY = Math.max(1, c.getInt(spanYIndex)); item.container = c.getInt(containerIndex); item.itemType = c.getInt(itemTypeIndex); item.screenId = c.getInt(screenIndex); item.title=c.getString(titleIndex); if(c.getString(intenIndex)!=null){ item.intent=new Intent(c.getString(intenIndex)); } items.add(item); } } catch (Exception e) { items.clear(); } finally { c.close(); } return items; }
Similarly, you can modify the URL,
I will not write the code.