contentProvider 测试使用

文件1

package com.gyarmy.banktest02;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

public class BankBackDoor extends ContentProvider {

	private static final int SUCCESS = 1;

	@Override
	public boolean onCreate() {
		// TODO Auto-generated method stub
		
		System.out.println("create0000000000000");
		
		return false;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public static UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
	static{
		matcher.addURI("com.gyarmy.db", "account", SUCCESS);
	}
	
	
	@Override
	public Uri insert(Uri uri, ContentValues values) {
		// TODO Auto-generated method stub
		
		if(matcher.match(uri) == SUCCESS){
			System.out.println("------------insert--------------");
			
		}else{
			
			System.out.println("------------xxxxxxx--------");
		}
		
		
		
		
		
		return null;
	}

	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

}

测试使用文件2


package com.gyarmy.ghost;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	
	public void add(View v){
		
		Uri uri = Uri.parse("content://com.gyarmy.db/account");
		ContentValues values= new ContentValues();
		ContentResolver resolver = getContentResolver();
		
		resolver.insert(uri, values);
		
		
	}
	
}

原文链接: contentProvider 测试使用 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-137.html )

发表评论

0则评论给“contentProvider 测试使用”