自定义的contentprovider 没有找到
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.contentprovider"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<provider
android:name=".MemberContentProvider"
android:authorities="com.contentprovider.membercontentprovider"/>
<activity
android:name="com.contentprovider.MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:mimeType="vnd.android.cursor.dir/vnd.mlgbcontentprovider.member" />
</intent-filter>
<intent-filter>
<data android:mimeType="vnd.android.cursor.item/vnd.mlgbcontentprovider.member" />
</intent-filter>
</activity>
</application>
</manifest>
package com.contentprovider;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button insertBut = null;
private Button updateBut = null;
private TextView textView = null;
private Button delete = null;
private Button queryBut = null;
private ListView listView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
this.insertBut = (Button)super.findViewById(R.id.button1);
this.insertBut.setOnClickListener(new InsertOnClickListener());
this.updateBut = (Button)super.findViewById(R.id.Button02);
this.updateBut.setOnClickListener(new UpdateOnClickListener());
this.textView = (TextView)super.findViewById(R.id.textView1);
this.delete = (Button)super.findViewById(R.id.button3);
this.delete.setOnClickListener(new DeleteOnClickListener());
this.queryBut = (Button)super.findViewById(R.id.button2);
this.queryBut.setOnClickListener(new QueryOnClickListener());
this.listView = (ListView)super.findViewById(R.id.listView1);
}
private class QueryOnClickListener implements OnClickListener{
@Override
public void onClick(View v) {
MainActivity.this.textView.setText("query");
Cursor result = MainActivity.this.testQuery(null);
MainActivity.this.startManagingCursor(result);
List<Map<String,Object>> models = new ArrayList<Map<String,Object>>();
for(result.moveToFirst();result.isAfterLast();result.moveToNext()){
Map<String,Object> model = new HashMap<String,Object>();
model.put("id", result.getInt(0));
model.put("name", result.getString(1));
model.put("age", result.getInt(2));
model.put("birthday", result.getString(3));
models.add(model);
System.out.println("####################");
}
MainActivity.this.listView.setAdapter(new SimpleAdapter(MainActivity.this,
models,
R.layout.member,
new String[]{"_id","name","age","birthday"},
new int[]{R.id.text1,R.id.text2,R.id.text3,R.id.text4}));
Toast.makeText(MainActivity.this, "query Success",
Toast.LENGTH_LONG).show();
}
}
.........
private Cursor testQuery(String id){
if(id == null||"".equals(id)){
return super.getContentResolver().query(MLGBDatabaseMetaData.MemberTableMetaData.CONTENT_URI,
null, null, null, MLGBDatabaseMetaData.MemberTableMetaData.SORT_ORDER);
}else{
return super.getContentResolver().query(Uri.
withAppendedPath(MLGBDatabaseMetaData.MemberTableMetaData.CONTENT_URI, id),
null, null, null, MLGBDatabaseMetaData.MemberTableMetaData.SORT_ORDER);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
package com.contentprovider;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
public class MemberContentProvider extends ContentProvider {
private static UriMatcher uriMatcher = null;//地址转换
private static final int GET_MEMBER_LIST = 1;
private static final int GET_MEMBER_ITEM = 2;
private SQLiteOpenHelper helper = null;
static{
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);//实例化
uriMatcher.addURI(MLGBDatabaseMetaData.AUTHORITY,
MLGBDatabaseMetaData.MemberTableMetaData.TABLE_NAME,
GET_MEMBER_LIST);
uriMatcher.addURI(MLGBDatabaseMetaData.AUTHORITY,
MLGBDatabaseMetaData.MemberTableMetaData.TABLE_NAME+"/#",
GET_MEMBER_ITEM);
}
public boolean onCreate() {
this.helper = new MyDatabaseHelper(super.getContext());
return true;
}
public String getType(Uri uri) {
switch(uriMatcher.match(uri)){
case GET_MEMBER_LIST:
return MLGBDatabaseMetaData.MemberTableMetaData.CONTACT_LIST;
case GET_MEMBER_ITEM:
return MLGBDatabaseMetaData.MemberTableMetaData.CONTACT_ITEM;
default:
throw new UnsupportedOperationException("Not Support Operation :"+ uri);
}
}
........
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteDatabase db = this.helper.getWritableDatabase();
switch(uriMatcher.match(uri)){
case GET_MEMBER_LIST:
return db.query(MLGBDatabaseMetaData.MemberTableMetaData.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder);
case GET_MEMBER_ITEM:
long id = ContentUris.parseId(uri);
String whereClause = "_id = " + id;
return db.query(MLGBDatabaseMetaData.MemberTableMetaData.TABLE_NAME, projection, whereClause, selectionArgs, null, null, sortOrder);
default:
throw new UnsupportedOperationException("Not Support Operation :"+ uri);
}
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
SQLiteDatabase db = this.helper.getWritableDatabase();
int result = 0;
switch(uriMatcher.match(uri)){
case GET_MEMBER_LIST:
result = db.update(MLGBDatabaseMetaData.MemberTableMetaData.TABLE_NAME, values, null, null);
break;
case GET_MEMBER_ITEM:
long id = ContentUris.parseId(uri);
String whereClause = "_id = " + id;
result = db.update(MLGBDatabaseMetaData.MemberTableMetaData.TABLE_NAME, values, whereClause, selectionArgs);
break;
default:
throw new UnsupportedOperationException("Not Support Operation :"+ uri);
}
return result ;
}
}
12-18 14:20:45.965: W/ActivityManager(70): No content provider found for:
12-18 14:20:46.116: W/ActivityManager(70): No content provider found for:
12-18 14:20:46.155: W/PackageParser(70): No actions in intent filter at /data/app/vmdl1630269891.tmp Binary XML file line #29
12-18 14:20:46.155: W/PackageParser(70): No actions in intent filter at /data/app/vmdl1630269891.tmp Binary XML file line #32
12-18 14:20:46.435: I/PackageManager(70): Removing non-system package:com.contentprovider
12-18 14:20:46.435: I/ActivityManager(70): Force stopping package com.contentprovider uid=10047
12-18 14:20:46.465: I/Process(70): Sending signal. PID: 481 SIG: 9
12-18 14:20:46.655: I/PackageManager(70): Package com.contentprovider codePath changed from /data/app/com.contentprovider-2.apk to /data/app/com.contentprovider-1.apk; Retaining data and using new
.....
现在的问题是,查询已经进入了MenberContentProvider类了,但是query返回的cursor,遍历发现没有数据.
然后在控制台的信息显示
No content provider found for:
究竟是哪里出错了?求解!!! --------------------编程问答-------------------- 你这个Uri MLGBDatabaseMetaData.MemberTableMetaData.CONTENT_URI的值是多少?
要跟你的autorities对应:
android:authorities="com.contentprovider.membercontentprovider" --------------------编程问答--------------------
其实是部署的时候出现这个错误
12-18 14:20:45.965: W/ActivityManager(70): No content provider found for:
12-18 14:20:46.116: W/ActivityManager(70): No content provider found for:
12-18 14:20:46.155: W/PackageParser(70): No actions in intent filter at /data/app/vmdl1630269891.tmp Binary XML file line #29
12-18 14:20:46.155: W/PackageParser(70): No actions in intent filter at /data/app/vmdl1630269891.tmp Binary XML file line #32
就是无法找到
后来我调用 联系人数据也是这个错,但是没有解决这个问题
补充:移动开发 , Android