码迷,mamicode.com
首页 > 数据库 > 详细

(8)Launcher3客制化之ContentProvider内容提供者,实现其他应用修改数据库更新等操作

时间:2014-10-19 00:04:42      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:android   blog   io   os   ar   java   sp   数据   2014   

首先添加两个权限

 <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内容提供者,实现其他应用修改数据库更新等操作

标签:android   blog   io   os   ar   java   sp   数据   2014   

原文地址:http://blog.csdn.net/xufeifandj/article/details/40227809

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!