不同应用程序提供的数据的获取显示—自定义ContentProvider
来源:互联网 发布:域名访问升级中 编辑:程序博客网 时间:2024/05/16 15:21
provider
002 android:name="com.course.day16course02.MyContentProvider"
003 android:authorities="com.course.day16course02.mycontentprovider"
004 android:exported="true">
005 provider
006
007
008 public class MySqliteHelper extends SQLiteOpenHelper {
009
010 private static final String DBNAME="products.db";
011 private static final int VERSION = 1;
012 public MySqliteHelper(Context context) {
013 super(context, DBNAME, null, VERSION);
014 // TODO Auto-generated constructor stub
015 }
016
017 @Override
018 public void onCreate(SQLiteDatabase db) {
019 // TODO Auto-generated method stub
020 String sql = "create table if not exists pro(_id integer primary key autoincrement,pname text,price text,provider text)";
021 db.execSQL(sql);
022 for(int i=0;i<</span>10;i++){
023 ContentValues cv = new ContentValues();
024 cv.put("pname", "andry"+i);
025 cv.put("price", "12"+i);
026 cv.put("provider", "联想"+i);
027 db.insert("pro", null, cv);
028 }
029 }
030
031 @Override
032 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
033 if(newVersion>oldVersion){
034 db.execSQL("drop table pro");
035 onCreate(db);
036 }
037
038
039
040 public class MyContentProvider extends ContentProvider {
041
042 private static UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
043 private static String autority="com.course.day16course02.mycontentprovider";
044 private MySqliteHelper helper;
045 //添加Uri的匹配规则
046 static{
047
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047