gpt4 book ai didi

android - 找不到内容提供商信息

转载 作者:搜寻专家 更新时间:2023-11-01 08:55:24 24 4
gpt4 key购买 nike

每次我点击一个按钮将数据添加到我的内容提供者时,我总是收到 LogCat 错误“找不到提供者信息”

根据过去关于相同问题的帖子,我检查并确保 Provider 在 Manifest XML 的 Application 部分内,并确保 Authorities 一直被写入。但我似乎仍然遇到同样的错误。

list XML:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ag.access"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="ag.access.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="ag.access.Farming"
android:label="@string/title_activity_farming"
android:parentActivityName="ag.access.MainActivity" >
<intent-filter>
<action android:name="ag.access.Farming" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ag.access.MainActivity" />
</activity>
<activity
android:name="ag.access.Dairy"
android:label="@string/title_activity_dairy"
android:parentActivityName="ag.access.MainActivity" >
<intent-filter>
<action android:name="ag.access.Dairy" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ag.access.MainActivity" />
</activity>
<activity
android:name="ag.access.Daily_log"
android:label="@string/title_activity_daily_log"
android:parentActivityName="ag.access.Dairy" >
<intent-filter>
<action android:name="ag.access.Daily_log" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ag.access.Dairy" />
</activity>
<activity
android:name="ag.access.Viewlogs"
android:label="@string/title_activity_viewlogs"
android:parentActivityName="ag.access.Daily_log" >
<intent-filter>
<action android:name="ag.access.Viewlogs" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ag.access.Daily_log" />
</activity>
<activity
android:name="ag.access.Add_Edit_Cows"
android:label="@string/title_activity_add__edit__cows"
android:parentActivityName="ag.access.Dairy" >
<intent-filter>
<action android:name="ag.access.Add_Edit_Cows" />
<category android:name="android.intent.category.DEFAULT" />

</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ag.access.Dairy" />
</activity>
<activity
android:name="ag.access.Viewcows"
android:label="@string/title_activity_viewcows"
android:parentActivityName="ag.access.Add_Edit_Cows" >
<intent-filter>
<action android:name="ag.access.Viewcows" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ag.access.Add_Edit_Cows" />
</activity>
<provider
android:name="ag.access.cowsdb.provider.Cows_Provider"
android:authorities="ag.access.cowsdb.provider.Cows_Provider">
</provider>
</application>
</manifest>

内容提供者 Java:

 package ag.access.cowsdb.provider;



import ag.access.cowsdb.Cowsdatabase;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
public class Cows_Provider extends ContentProvider {

private Cowsdatabase cowsdbh;

private static final String Authority =
"ag.access.cowsdb.Cows_Provider";
private static final String Cows = "Cows";
public static final Uri Content_Uri = Uri.parse("content://" + Authority + "/" + Cows);
public static final int COWS = 1;
public static final int COWS_ID = 2;
private static final UriMatcher cURIMatcher =
new UriMatcher(UriMatcher.NO_MATCH);
static {
cURIMatcher.addURI(Authority, Cows, COWS);
cURIMatcher.addURI(Authority, Cows + "/#", COWS_ID);
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {

int uriType = cURIMatcher.match(uri);
SQLiteDatabase mysqldb = cowsdbh.getWritableDatabase();
int rowsDeleted = 0;

switch (uriType) {
case COWS:
rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, selection, selectionArgs);
break;
case COWS_ID:
String id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, Cowsdatabase.Key_Cow + "=" + id, null);
} else {
rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, Cowsdatabase.Key_Cow + "=" + id + " and " + selection, selectionArgs);
}
break;
default:
throw new IllegalArgumentException("Unknow URI: " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return rowsDeleted;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
int uriType = cURIMatcher.match(uri);

SQLiteDatabase mydb = cowsdbh.getWritableDatabase();

long id = 0;
switch (uriType) {
case COWS:
id = mydb.insert(Cowsdatabase.DATABASE_TABLE, null, values);
break;
default:
throw new IllegalArgumentException("Unknow Uri: " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return Uri.parse(Cows + "/" + id);
}
@Override
public boolean onCreate() {
cowsdbh = new Cowsdatabase(getContext(), null, null, 1);
return false;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(cowsdbh.DATABASE_TABLE);

int uriType = cURIMatcher.match(uri);

switch (uriType) {
case COWS_ID:
qb.appendWhere(cowsdbh.Key_Cow + "=" + uri.getLastPathSegment());
break;
case COWS:
break;
default:
throw new IllegalArgumentException("Unknown URI");

}
Cursor cursor = qb.query(cowsdbh.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
int uriType = cURIMatcher.match(uri);
SQLiteDatabase mysqldb = cowsdbh.getWritableDatabase();
int rowsUpdated = 0;

switch (uriType) {
case COWS:
rowsUpdated = mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, selection, selectionArgs);
break;
case COWS_ID:
String id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsUpdated =
mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, Cowsdatabase.Key_Cow + "=" + id, null);
} else {
rowsUpdated =
mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, Cowsdatabase.Key_Cow + "=" + id + " and " + selection, selectionArgs);
}
break;
default:
throw new IllegalArgumentException("Unknown URI:" + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return rowsUpdated;
}
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub
return null;
}
}

请帮我解决这个问题。

最佳答案

在类里面,您将权限值设置为 "ag.access.cowsdb.Cows_Provider",而在 list 文件中则不同 "ag.access.cowsdb.provider.Cows_Provider"

请设置相同的权限值

关于android - 找不到内容提供商信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19396304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com