`
gnibrE
  • 浏览: 138106 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

建立自己的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;
    }



}





最后menifest.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> 






分享到:
评论
1 楼 javacode23 2010-11-29  
您好,我自己写了一个ContentProvider-MyProvider在mainfest.xml文件中通过
android:name="android.permission.WRITE_MYPERMISSION"
设置了写权限,然后通过自己写的另一个apk去访问这个provider的时候,通过在mainfest>xml文件中添加
<uses-permission android:name="android.permission.WRITE_MYPERMISSION">
这样设置了访问权限,但是为什么我的程序已运行还是报错说缺少访问权限啊?您给指点一下?谢谢

相关推荐

    androdi ContentProvider和Uri详解

    每个ContentProvider都有一个唯一的URI(统一资源标识符)来标识自己,这个URI用于定位ContentProvider并指定要操作的数据。 接下来,我们谈谈Uri。Uri(Uniform Resource Identifier)是互联网上的资源标识符,而...

    android 创建数据库contentprovider

    在Android系统中,ContentProvider是一种重要的组件,它允许应用程序之间共享数据。`android 创建数据库contentprovider`这个主题主要涉及如何创建一个自定义的ContentProvider来管理数据库中的数据,并实现跨应用的...

    Android-Intent-数据存取-ContentProvider.doc

    类似地,一个 Intent 可以传递给 Context.bindService(Intent,ServiceConnection,int) 去建立调用组件和目标服务之间的连接。 2. Intent 的构成 要在不同的 Activity 之间传递数据,就要在 Intent 中包含相应的...

    自定义ContentProvider

    自定义ContentProvider意味着开发者根据需求创建自己的数据访问接口,实现对特定数据源(如SQLite数据库、文件系统等)的操作。本篇将深入探讨如何自定义ContentProvider以及其在实际开发中的应用。 首先,我们了解...

    Android学习 ContentProvider数据更新与Observer模式.doc

    **Observer模式**的核心在于建立一种一对多的关系,当一个对象(称为Subject)的状态发生改变时,所有依赖于这个对象的其他对象(称为Observer)都会得到通知并自动更新自己。这种模式在Android中常用于实时数据更新...

    ContentProvider

    通过ContentProvider,一个应用可以将自己的数据暴露出去,让其他应用访问,反之亦然。本示例"ContentProvider"聚焦于如何创建和使用ContentProvider进行数据的更新、插入和删除操作。 首先,我们需要了解...

    android中contentprovider通讯录

    在这里,我们可以建立与数据源(如SQLite数据库)的连接。 2. `query()`:处理来自ContentResolver的查询请求,返回一个`Cursor`对象,其中包含查询结果。参数包括URI(标识要查询的数据)、projection(列名)、...

    contentProvider,sqlit例子

    通过继承SQLiteOpenHelper,我们可以重写onCreate()和onUpgrade()方法,分别处理数据库首次创建时的表结构建立和版本升级时的表结构调整。 在"ch4-contentProvider"目录下,可能包含以下文件: 1. `DatabaseHelper...

    实验8 SQLite数据库与ContentProvider.doc

    本实验主要目的就是掌握SQLite数据库的建立和操作方法,并理解ContentProvider的用途和原理。 知识点1:SQLite数据库的建立 在本实验中,我们使用Android Studio创建了一个名为test.db的SQLite数据库,并建立了一...

    ContentProvider使用

    ### ContentProvider 使用详解 #### 一、ContentProvider概念与作用 ...通过本文的学习,你应该能够理解如何在自己的应用程序中实现数据共享,并利用 ContentProvider 提供的高级特性来增强应用程序的功能性和灵活性。

    android 通过ContentProvider实现sqlite数据库共享

    首先,我们需要创建一个继承自SQLiteOpenHelper的类,负责数据库的创建、升级,以及表的建立。例如: ```java public class MyDatabaseHelper extends SQLiteOpenHelper { // 数据库版本号 private static final ...

    F06_d_观摩_ContentProvider架构与DB引擎移植方法_ok1

    这里使用了JDBC的方式,通过加载Linter数据库的驱动并建立连接。 - 类中还可能包含其他的数据库操作方法,如`query()`, `insert()`, `update()`, `delete()`,这些方法映射到对Linter数据库的相应操作。 2. **...

    Android中使用Content Provider组件访问通讯录中的联系人和添加联系人案例详解

    每个Content Provider都需要实现`android.content.ContentProvider`类,并重写其关键方法,如`onCreate()`, `query()`, `insert()`, `update()`和`delete()`。这些方法分别对应于创建、查询、插入、更新和删除数据的...

    Android学习之手机通讯录

    开发者可以通过自定义ContentProvider来暴露自己的数据,使得其他应用可以像操作系统数据一样操作这些数据。 在手机通讯录的查询过程中,我们需要实现UriMatcher和CursorLoader。UriMatcher用于匹配不同的Uri请求,...

    shareDatabase.rar

    在我们的案例中,我们可以创建一个应用(如testb),在这个应用中建立并管理数据库,并实现ContentProvider来暴露其数据库操作。ContentProvider通过URI(统一资源标识符)提供对数据的增删查改接口,其他应用(如...

    建立能与访问者进行相互通信的本地服务

    Service是Android四大组件(Activity、Service、BroadcastReceiver、ContentProvider)之一,主要用于在后台执行长时间运行的操作,而无需用户交互界面。以下是对这个主题的详细解释: 1. **Service基础概念**: ...

    ContentProvid

    4. 在`onCreate()`方法中初始化与数据相关的逻辑,例如建立数据库连接或初始化数据存储。 5. 配置AndroidManifest.xml文件,声明你的`ContentProvider`。添加`&lt;provider&gt;`标签,设置`android:name`为`...

Global site tag (gtag.js) - Google Analytics