独自のContentProviderの作成


public class LauncherLiveFolderProvider extends ContentProvider
//自分でクラスを作成し、ContentProviderから継承するには、デフォルトでこれらの実装方法があります.
//データを読み取るだけなら、queryやgettypeなどを実現するのが基本です.
//
最近書いたsmsとbookmarkをlivefolderのコードに変えて、ahomeとcontactsのソースコードを参考にして作ったのです
provider定義の比較的勝手で、少し醜いようです.の
ソースコードはあまり読んでいませんが、smsの部分は完全に自分でデータベースの表の項目を見てから勝手に間に合いました.
1.LauncherLiveFolderAdapterURI.java. すべて変数です.

package g.LauncherLiveFolderAdapter;
import android.net.Uri;


public class LauncherLiveFolderAdapterURI {
    
    public static final String AUTHORITY_SMS="livefolder.sms";
    public static final String AUTHORITY_BOOKMARK="livefolder.browser";
    
    public static final Uri BOOKMARK_ALL_CONTNET_URI = Uri.parse("content://"+AUTHORITY_BOOKMARK+"/bookmarks/all");
    public static final Uri BOOKMARK_RECENTVIST_CONTNET_URI = Uri.parse("content://"+AUTHORITY_BOOKMARK+"/bookmarks/recently_visited");
    public static final Uri BOOKMARK_MOSTVIST_CONTNET_URI = Uri.parse("content://"+AUTHORITY_BOOKMARK+"/bookmarks/most_visited");
    
    public static final Uri SMS_ALL_CONTENT_URI = Uri.parse("content://"+AUTHORITY_SMS+"/all");                   // all  = inbox + sent
    public static final Uri SMS_INBOX_CONTENT_URI = Uri.parse("content://"+AUTHORITY_SMS+"/inbox");      
    public static final Uri SMS_SENT_CONTENT_URI = Uri.parse("content://"+AUTHORITY_SMS+"/sent");
    public static final Uri SMS_UNREAD_CONTENT_URI = Uri.parse("content://"+AUTHORITY_SMS+"/unread");            // unread < inbox
    
    
    public static final Uri CONTNET_SMS_URI =  Uri.parse("content://"+AUTHORITY_SMS);
    
    public static final int SMS_ALL = 101;
    public static final int SMS_INBOX = 102;
    public static final int SMS_UNREAD = 103;
    public static final int SMS_SENT = 104;    
    public static final int BOOKMARK_ALL = 111;
    public static final int BOOKMARK_RECENT = 112;
    public static final int BOOKMARK_MOST = 113;
    
    public static final String BOOKMARK_CONTENT_TYPE = "vnd.android.cursor.dir/bookmark";    
    public static final String BOOKMARK_CONTENT_TYPE_ITEM=  "vnd.android.cursor.item/bookmark";             
    public static final String SMS_CONTENT_TYPE = "vnd.android.cursor.dir/mms-sms";
    public static final String SMS_CONTENT_TYPE_ITEM="vnd.android.cursor.item/mms-sms";
    
}



2.LauncherLiveFolderAdapter.JAvaはlivefolderオプションmenuでアプリケーションを満たすためのやつです


package g.LauncherLiveFolderAdapter;

import android.app.Activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
import android.provider.LiveFolders;

public class LauncherLiveFolderAdapter {

    public static class AllBookmark extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Intent intent = getIntent();
            final String action = intent.getAction();
            String s = "All bookmarks"; // name returned to launcher. show on the main 
            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this,
                        LauncherLiveFolderAdapterURI.BOOKMARK_ALL_CONTNET_URI, s, R.drawable.icon));
            } else {
                setResult(RESULT_CANCELED);
            }
            finish();
        }
    }

    public static class MostBookmark extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Intent intent = getIntent();
            final String action = intent.getAction();
            String s = "Most visited bookmarks";
            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this,
                        LauncherLiveFolderAdapterURI.BOOKMARK_MOSTVIST_CONTNET_URI, s,
                        R.drawable.icon));
            } else {
                setResult(RESULT_CANCELED);
            }
            finish();
        }
    }

    public static class RecentBookmark extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Intent intent = getIntent();
            final String action = intent.getAction();
            String s = "Recently visited bookmarks";
            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this,
                        LauncherLiveFolderAdapterURI.BOOKMARK_RECENTVIST_CONTNET_URI, s,
                        R.drawable.icon));
            } else {
                setResult(RESULT_CANCELED);
            }
            finish();
        }
    }
    
    public static class AllSMS extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Intent intent = getIntent();
            final String action = intent.getAction();
            String s = "ALL SMS";
            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this,
                        LauncherLiveFolderAdapterURI.SMS_ALL_CONTENT_URI, s,
                        R.drawable.icon));
            } else {
                setResult(RESULT_CANCELED);
            }
            finish();
        }
    }
    
    public static class InboxSMS extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Intent intent = getIntent();
            final String action = intent.getAction();
            String s = "Inbox SMS";
            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this,
                        LauncherLiveFolderAdapterURI.SMS_INBOX_CONTENT_URI, s,
                        R.drawable.icon));
            } else {
                setResult(RESULT_CANCELED);
            }
            finish();
        }
    }
    
    public static class SentSMS extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Intent intent = getIntent();
            final String action = intent.getAction();
            String s = "Sent SMS";
            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this,
                        LauncherLiveFolderAdapterURI.SMS_SENT_CONTENT_URI, s,
                        R.drawable.icon));
            } else {
                setResult(RESULT_CANCELED);
            }
            finish();
        }
    }
    
    public static class UnreadSMS extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Intent intent = getIntent();
            final String action = intent.getAction();
            String s = "Unread SMS";
            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this,
                        LauncherLiveFolderAdapterURI.SMS_UNREAD_CONTENT_URI, s,
                        R.drawable.icon));
            } else {
                setResult(RESULT_CANCELED);
            }
            finish();
        }
    }
    

    private static Intent createLiveFolder(Context context, Uri uri, String name, int icon) {
        final Intent intent = new Intent();
        intent.setData(uri);
        intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);
        intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, Intent.ShortcutIconResource
                .fromContext(context, icon));
        intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);
        return intent;
    }
}


3 . LauncherLiveFolderProvider.JAva、読めばいいので、簡単です.


package g.LauncherLiveFolderAdapter;

import android.content.ContentProvider;

import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.provider.Browser;
import android.provider.LiveFolders;

public class LauncherLiveFolderProvider extends ContentProvider {
    
//    public static final String AUTHORITY_SMS="livefolder.sms";
//    public static final String AUTHORITY_BOOKMARK="livefolder.browser";    
    
    // used to query  .  provided by system
    public static final Uri SMS_URI_ALL = Uri.parse("content://sms/"); 
    public static final Uri SMS_URI_INBOX = Uri.parse("content://sms/inbox");
    public static final Uri SMS_URI_SENT= Uri.parse("content://sms/sent");
    
    public static final String SMS_CONVERSATION_URI= "content://mms-sms/conversations/";

    
    
    private static final UriMatcher sMatcher;
    static{
        sMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        sMatcher.addURI(LauncherLiveFolderAdapterURI.AUTHORITY_BOOKMARK, "bookmarks/all", LauncherLiveFolderAdapterURI.BOOKMARK_ALL);
        sMatcher.addURI(LauncherLiveFolderAdapterURI.AUTHORITY_BOOKMARK, "bookmarks/most_visited", LauncherLiveFolderAdapterURI.BOOKMARK_MOST);
        sMatcher.addURI(LauncherLiveFolderAdapterURI.AUTHORITY_BOOKMARK, "bookmarks/recently_visited", LauncherLiveFolderAdapterURI.BOOKMARK_RECENT);        
        sMatcher.addURI(LauncherLiveFolderAdapterURI.AUTHORITY_SMS, "all", LauncherLiveFolderAdapterURI.SMS_ALL);
        sMatcher.addURI(LauncherLiveFolderAdapterURI.AUTHORITY_SMS, "sent", LauncherLiveFolderAdapterURI.SMS_SENT);
        sMatcher.addURI(LauncherLiveFolderAdapterURI.AUTHORITY_SMS, "unread", LauncherLiveFolderAdapterURI.SMS_UNREAD);
        sMatcher.addURI(LauncherLiveFolderAdapterURI.AUTHORITY_SMS, "inbox", LauncherLiveFolderAdapterURI.SMS_INBOX);        
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        throw new NoSuchMethodError();
    }    
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        throw new NoSuchMethodError();
    }
    @Override
    public boolean onCreate() {
        return true;
    }    
    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        throw new NoSuchMethodError();
    }
    @Override
    public String getType(Uri uri) {
        switch(sMatcher.match(uri)){
            case LauncherLiveFolderAdapterURI.BOOKMARK_ALL:
                return LauncherLiveFolderAdapterURI.BOOKMARK_CONTENT_TYPE;                
            case LauncherLiveFolderAdapterURI.BOOKMARK_MOST:
                return LauncherLiveFolderAdapterURI.BOOKMARK_CONTENT_TYPE;
            case LauncherLiveFolderAdapterURI.BOOKMARK_RECENT:
                return LauncherLiveFolderAdapterURI.BOOKMARK_CONTENT_TYPE;
            case LauncherLiveFolderAdapterURI.SMS_ALL:
                return LauncherLiveFolderAdapterURI.SMS_CONTENT_TYPE;                
            case LauncherLiveFolderAdapterURI.SMS_INBOX:
                return LauncherLiveFolderAdapterURI.SMS_CONTENT_TYPE;
            case LauncherLiveFolderAdapterURI.SMS_SENT:
                return LauncherLiveFolderAdapterURI.SMS_CONTENT_TYPE;
            case LauncherLiveFolderAdapterURI.SMS_UNREAD:
                return LauncherLiveFolderAdapterURI.SMS_CONTENT_TYPE;
                default:
                    throw new IllegalArgumentException("Unknown URI g:"+uri);
        }
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
            String sortOrder) {
        
        Uri query_uri;
        String[] prejection;
        int id_index=0;
        int name_index=0;
        int description_index=0;
        int intent_uri_type = -1;
        String intent_uri="";
        
        
        int matched = sMatcher.match(uri);
        switch(matched){
            case LauncherLiveFolderAdapterURI.BOOKMARK_ALL:
                query_uri = Browser.BOOKMARKS_URI;
                prejection = Browser.HISTORY_PROJECTION;
                id_index = Browser.HISTORY_PROJECTION_ID_INDEX;
                name_index = Browser.HISTORY_PROJECTION_TITLE_INDEX; 
                description_index = Browser.HISTORY_PROJECTION_URL_INDEX;
                intent_uri_type = Browser.HISTORY_PROJECTION_URL_INDEX;
                selection = "bookmark=1";       //boookmarked
                sortOrder = null;
                break;                
            case LauncherLiveFolderAdapterURI.BOOKMARK_MOST:
                query_uri = Browser.BOOKMARKS_URI;
                prejection = Browser.HISTORY_PROJECTION;
                id_index = Browser.HISTORY_PROJECTION_ID_INDEX;
                name_index = Browser.HISTORY_PROJECTION_TITLE_INDEX;
                description_index = Browser.HISTORY_PROJECTION_URL_INDEX;        
                intent_uri_type = Browser.HISTORY_PROJECTION_URL_INDEX;
                selection = "visits > 0";
                sortOrder = "visits desc";      //most visited
                break;                
            case LauncherLiveFolderAdapterURI.BOOKMARK_RECENT:                
                query_uri = Browser.BOOKMARKS_URI;
                prejection = Browser.HISTORY_PROJECTION;
                id_index = Browser.HISTORY_PROJECTION_ID_INDEX;
                name_index = Browser.HISTORY_PROJECTION_TITLE_INDEX;
                description_index = Browser.HISTORY_PROJECTION_URL_INDEX;
                intent_uri_type = Browser.HISTORY_PROJECTION_URL_INDEX;
                selection = "date > 0";
                sortOrder = "date desc";        // most recently visited
                break;                
                // for sms
            case LauncherLiveFolderAdapterURI.SMS_ALL:
                query_uri = SMS_URI_ALL;
                id_index = 0;
                name_index = 11; //body
                description_index = 4; // person
                intent_uri_type = 2; //type . 
                prejection = new String[]{"*"};
                sortOrder = null;
                break;                                
            case LauncherLiveFolderAdapterURI.SMS_INBOX:
                query_uri = SMS_URI_INBOX;
                id_index = 0;
                name_index = 11; //body
                description_index = 4; // person
                intent_uri_type = 2; //type . 
                prejection = new String[]{"*"};
                sortOrder = null;
                break;
            case LauncherLiveFolderAdapterURI.SMS_SENT:
                query_uri = SMS_URI_SENT;
                id_index = 0;
                name_index = 11; //body
                description_index = 4; // person
                intent_uri_type = 2; //type . 
                prejection = new String[]{"*"};
                sortOrder = null;
                break;
            case LauncherLiveFolderAdapterURI.SMS_UNREAD:
                query_uri = SMS_URI_INBOX;  // inbox, unread
                name_index = 11; //body
                description_index = 4; // person
                intent_uri_type = 2; //type . 
                prejection = new String[]{"*"};
                id_index = 0;
                sortOrder = null;
                break;
                default:
                    throw new IllegalArgumentException("Unknown URI g:"+uri);
     }
        Cursor c = getContext().getContentResolver().query(query_uri,
                prejection, selection,null, sortOrder);    // DESC
       
        String[] liveFolderColumnNames = {
                LiveFolders._ID, 
                LiveFolders.NAME, 
                LiveFolders.DESCRIPTION,
                LiveFolders.ICON_PACKAGE, //icon added
                LiveFolders.ICON_RESOURCE, //
                LiveFolders.INTENT
        };
        MatrixCursor mc = new MatrixCursor(liveFolderColumnNames, c.getCount());

        
        
        
        int columnCount = c.getColumnNames().length;
        while (c.moveToNext()) {
            
            if(intent_uri_type==1)
                intent_uri =c.getString(Browser.HISTORY_PROJECTION_URL_INDEX);
            else
                intent_uri = SMS_CONVERSATION_URI+c.getString(1);// conversation_id @ sms , don't know any  statics 
            
            Object[] row = {
                    c.getString(id_index), // for id
                    c.getString(name_index), // for name
                    c.getString(description_index),//for description
                    getContext().getPackageName(), //icon package
                    R.drawable.icon, //icon resource                                
                    Uri.parse(intent_uri)
                     //intent type uri  // name  to find  that right activity //     for bookmarks,  uri is like    http:// .....
                    
            };            
            mc.addRow(row);
        }
        return mc;
    }



}



最後にxmlファイル


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
	package="g.LauncherLiveFolderAdapter" android:versionCode="1"
	android:versionName="1.0">
	<application android:icon="@drawable/icon" android:label="@string/app_name">

		<provider android:name=".LauncherLiveFolderProvider"
			android:authorities="livefolder.browser" />
			<provider android:name=".LauncherLiveFolderProvider"
			android:authorities="livefolder.sms" />
		<activity android:name=".LauncherLiveFolderAdapter$AllBookmark"		
		android:label="All Bookmark"				
			android:icon="@drawable/icon">
			<intent-filter>
				<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>
		</activity>
		
				<activity android:name=".LauncherLiveFolderAdapter$MostBookmark"
				android:label="Most Visited Bookmark"						
			android:icon="@drawable/icon">
			<intent-filter>
				<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>
		</activity>
		
				<activity android:name=".LauncherLiveFolderAdapter$RecentBookmark"			
				android:label="Recently Visited Bookmark"
			android:icon="@drawable/icon">
			<intent-filter>
				<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>
		</activity>

				<activity android:name=".LauncherLiveFolderAdapter$AllSMS"			
				android:label="All SMS"
			android:icon="@drawable/icon">
			<intent-filter>
				<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>
		</activity>
		
						<activity android:name=".LauncherLiveFolderAdapter$SentSMS"			
						android:label="SMS SENT"
			android:icon="@drawable/icon">
			<intent-filter>
				<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>
		</activity>
		
								<activity android:name=".LauncherLiveFolderAdapter$InboxSMS"
								android:label="SMS INBOX"			
			android:icon="@drawable/icon">
			<intent-filter>
				<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>
		</activity>
		
								<activity android:name=".LauncherLiveFolderAdapter$UnreadSMS"
								android:label="SMS UNREAD"			
			android:icon="@drawable/icon">
			<intent-filter>
				<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>
		</activity>


	</application>
	<uses-sdk android:minSdkVersion="3" />
	<uses-permission
		android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"></uses-permission>
		    <uses-permission android:name="android.permission.READ_SMS"/>

</manifest>