我一直在尝试在我的应用中添加内容提供商,但它显示的网址未找到。我尝试在Android清单文件中添加标记,并将权限地址设置为我的包地址,但结果仍然相同。有数据库和合同java文件也有,但问题仅在于FCMprovider.java。请帮助
错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{fcm.bio.fcm/fcm.bio.MainActivity}: java.lang.IllegalArgumentException: Unknown URL content://fcm.bio.ayushsharma.fcm.provider.provider/messages
FCMprovider.java
@ContentProvider(
authority = FCMprovider.AUTHORITY,
database = FCMdatabase.class
)
public class FCMprovider {
public static final String
AUTHORITY="fcm.bio.ayushsharma.fcm.provider.provider";
@TableEndpoint(table = FCMdatabase.FCM_MESSAGES)
public static class FCMmessages{
@ContentUri(
path = "messages",
type="vnd.android.cursor.dir/message",
defaultSort = FCMcontract.COLUMN_DATE+"DESC")
public static final Uri CONTENT_URI=Uri.parse("content://"+ AUTHORITY + "/messages");
}
}
AndroidManifest.java
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<provider
android:authorities="com.bio.ayushsharma.fcm.provider.provider"
android:name=".provider.generated.FCMprovider"
android:exported="false"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".following.followingPreferenceActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
</application>
mainActivity.java
public class MainActivity extends AppCompatActivity implements
LoaderManager.LoaderCallbacks<Cursor> {
private static String LOG_TAG = MainActivity.class.getSimpleName();
private static final int LOADER_ID_MESSAGES = 0;
RecyclerView mRecyclerView;
LinearLayoutManager mLayoutManager;
SquawkAdapter mAdapter;
static final String[] MESSAGES_PROJECTION = {
SquawkContract.COLUMN_AUTHOR,
SquawkContract.COLUMN_MESSAGE,
SquawkContract.COLUMN_DATE,
SquawkContract.COLUMN_AUTHOR_KEY
};
static final int COL_NUM_AUTHOR = 0;
static final int COL_NUM_MESSAGE = 1;
static final int COL_NUM_DATE = 2;
static final int COL_NUM_AUTHOR_KEY = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.squawks_recycler_view);
// Use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// Use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
// Add dividers
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
mRecyclerView.getContext(),
mLayoutManager.getOrientation());
mRecyclerView.addItemDecoration(dividerItemDecoration);
// Specify an adapter
mAdapter = new SquawkAdapter();
mRecyclerView.setAdapter(mAdapter);
// Start the loader
getSupportLoaderManager().initLoader(LOADER_ID_MESSAGES, null, this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_following_preferences) {
// Opens the following activity when the menu icon is pressed
Intent startFollowingActivity = new Intent(this, FollowingPreferenceActivity.class);
startActivity(startFollowingActivity);
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Loader callbacks
*/
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// This method generates a selection off of only the current followers
String selection = SquawkContract.createSelectionForCurrentFollowers(
PreferenceManager.getDefaultSharedPreferences(this));
Log.d(LOG_TAG, "Selection is " + selection);
return new CursorLoader(this, SquawkProvider.SquawkMessages.CONTENT_URI,
MESSAGES_PROJECTION, selection, null, SquawkContract.COLUMN_DATE + " DESC");
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
}
}
答案 0 :(得分:2)
android:authorities="com.bio.ayushsharma.fcm.provider.provider"
这从com.
AUTHORITY="fcm.bio.ayushsharma.fcm.provider.provider";
这从fcm
开始。
这些不一样,它们必须相同。所以,改变其中一个。