In my application I am using content provider media.image.external to get images uri and then write those uri to my Sqlite database.
But I want that my Sqlite database gets updated ( of any image add,delete,rename) in background as soon as the content provider media.image is updated.
Related
I Want to select a image from the gallery and save its URI to a database and then later retrieve it in another activity of the same project.
I used ACTION_PICK intent and in OnActivityResult, i got the URI of the image using intent.getData(). I saved this URI to the SQLite database.( As a string)
Later, when retrieving it from the database, i get an error that says :
Permission Denial:opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from ProcessRecord
What could be the problem?
I have created my own Sqlite database with all the columns that are there in Content Provider Media Image.
Now I want to save(add) all the rows (data) of Content Provider to my sqlite database.
So please help me as to which is the best memory effective and fastest way to do this.
I want to run this process in background using a service class.
Edit:-
Androids Content Provider Media/External/Image/Media Database Columns:-
_id , _data, _size, _display-name , etc.....
My presentation Layer to Display:-
_data, _size, _display-name , _custom-column
Custome Column I get after processing _data of each image, and this process is a bit time taking. So I want to do that in background and save it (mapping _custom-column with _id) so that whenever the application is launched I just present it to user.
In my application I have a sqlite database.The columns in this database are :- id, data,date-added, mydescription.
And android content provider Media.Image.External has following columns in its database:- _id , _data , _title , _date-added ,....and so on.
I want that whenever application is launched, my database gets synced with content provider database(only id, data, and date-added columns). So If android content provider database has an addition of row, my database also adds that row and if any row is deleted, then my database also deletes that row.
So how to achieve this thing.
Thanks
You can use Application class.
It is a singleton and guaranteed to start before your any Activity.
Inside it query data with the help of Cursor Loader. If the content provider correctly implemented you will get new data for every update in the DB.
I have multiple cursor loaders set up pointing to different URIs in my content provider and they work without any issues. Each loader is for a specific table in my database.
However I have now created a new URI in my content provider to execute a join query on my tables. I have created a new loader that points to the URI to be used for performing a join query but the loader doesn't update the UI.
If I close the app and then open it then the new data appears but after inserting new data in one activity and then returning to my main activity, the data hasn't updated. The loader isn't being called despite the database have new data inserted to it.
I am calling cursor.setNotificationUri(getContext().getContentResolver(), uri); for my new join URI.
Is there any particular reason why this isn't working? Like I said the loaders work fine for standard querying of individual tables but a loader with a join query doesn't.
Is it that a loader can only listen to a single table being updated hence why it can't listen to the join?
EDIT:
Some more information about the workflow...
Activity 1 reads data using a join query of the separate tables and displays to the UI
Activity 2 inserts data into separate tables to the database
Activity 1 launches Activity 2 which finishes after inserting data
Activity 1 has a loaders to update the UI. Loaders reading from individual tables works fine but a loader reading from a join query doesn't get called when data is updated. It is only called when the activity is created.
I Know this question was asked a long time ago but hopefully it will help some others experiencing the same problem... I had exactly the same issue
In your Query method in your Content Provider Class, before you set the notification Uri. Make sure the Update and Delete Uri's are the same as the query Uri's.
uri = Uri.parse("content://com.casselsinthecloud.cloudbeats.provider/playlist_contents");
Then call setNotificationUri(...) with the new Uri..
cursor.setNotificationUri(getContext().getContentResolver(), uri);
This will ensure the CursorLoader is updated dynamically..
I am new to android so have very less idea about working of images in sqlite db. I am creating an app in which i will be creating a db with pre-filled data that means i would be putting that data-filled db in assets folder and user will start using it directly once the app is installed.
So i have around 186 images of flags from different countries, which i need to show in a custom listview. Can you tell me how to store all images in sqlite db and get it back to show on listview?
I tried using some IDE for inserting images in db but their decoding doesn't work.
Please help!!!
try this First of all you have to store all images in blob datatype into sqlite database then for retrieving from database user following code
query_compnay_id="Select * From "+mStaticValues.company_master;
mCursor_company_detail=mDatabaseConnectionAPI.ExecuteQueryGetCursor((query_compnay_id));
mCursor_company_detail.moveToFirst();
byte[] by =mCursor_company_detail.getBlob(mCursor_company_detail.getColumnIndex(mStaticValues.image_data));
mBitmap=BitmapFactory.decodeByteArray(by, 0, by.length, null);