首页 > 代码库 > (8)Launcher3客制化之ContentProvider内容提供者,实现其他应用修改数据库更新等操作
(8)Launcher3客制化之ContentProvider内容提供者,实现其他应用修改数据库更新等操作
首先添加两个权限
<uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS"/>
<uses-permission android:name="com.android.launcher3.permission.WRITE_SETTINGS"/>
这两个是修改 桌面的数据库的权限
不添加就修改不了哦
直接通过内容提供者获取数据,
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; }修改内容同理通过对于的URL进行修改,
具体我就不进行代码编写了。
(8)Launcher3客制化之ContentProvider内容提供者,实现其他应用修改数据库更新等操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。