Reputation: 21
I was 'trying to use Shared Preferences in ContentProvider'..........It seems that it is not possible.......
But at the end I want to send an id (int or Sting) from My_Activity to Content Provider for that I was Using SharedP......Any other alternative
I am calling CP like this
PackageManager pm = getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA))
{
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT,MyFileContentProvider.CONTENT_URI);
startActivityForResult(i, CAMERA_RESULT);
}
else
{
Toast.makeText(getBaseContext(), "Camera is not available", Toast.LENGTH_LONG).show();
}
Upvotes: 0
Views: 927
Reputation: 3872
The purpose of SharedPreferences
is to store configuration data, it's not a communication channel.
If the id you want to pass is related to the action that's to be performed you can append it as a query parameter to your Uri
using Uri.Builder.appendQueryParameter(String, String)
.
Your code will look like this:
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT,MyFileContentProvider.CONTENT_URI
.buildUpon().appendQueryParameter("id", "123456").build());
The resulting Uri
will look like this:
content://YOUR.AUTHORITY/YOUR/PATH?id=123456
In your ContentProvider
you can use Uri.getQueryParameter(String)
to retrieve the parameter value.
Upvotes: 1