zoukankan      html  css  js  c++  java
  • (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进行改动。

    详细我就不进行代码编写了。



  • 相关阅读:
    poj 2676 Suduku (dfs)
    poj 1562 Oil Deposits (dfs)
    poj 2907 Collecting Beepers (dfs)
    poj 1655 Balancing Act (树形dfs)
    poj 3411 Paid Roads (dfs)
    hdu 2896 病毒侵袭 (AC)
    hdu 3065 病毒侵袭持续中 (AC)
    poj 2251 Dungeon Master (bfs)
    java中debug使用
    Swing入门级小项目总结
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5342666.html
Copyright © 2011-2022 走看看