B程序:通过A程序中继承ContentProvider的类提供的uri访问到A程序的数据
package cn.mrzhu.test24x;
import Android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//取得ContentResolver对象
ContentResolver cr = getContentResolver();
//指定uri并指定操作哪个表
Uri uri = Uri.parse("content://cn.mrzhu.test24/test1");
//执行query方法返回一个结果集
Cursor cs = cr.query(uri, null, null, null, null);
//遍历结果集,取出数据
while(cs.moveToNext()){
Log.i("System.out", "_id" + cs.getInt(0) + "name" + cs.getString(1) + "age" + cs.getInt(2));
}
}
}