I want to show to the user his latest photos or screenshot made by him in my app.
String[] projection = new String[]{
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.MIME_TYPE
};
final Cursor cursor = getActivity().getContentResolver()
.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
In order to get the latest photos on the phone i use Cursor.
How can i check if the picture/screenshot was taken on this phone?
I don't want unrelated WhatsApp photos (or other apps) to be shown, only photos from camera roll and screenshots.
I think this post https://stackoverflow.com/a/4495753/2014374 should help you finding your answer.
It used content resolver over Images.Media.EXTERNAL_CONTENT_URI and filters the results by getting the Media.BUCKET_ID from media bucket name "/DCIM/Camera"; Hope this helps.
Related
Hi i have an app which reads the browserhistory with this code
String[] proj = new String[] { Browser.BookmarkColumns.DATE, Browser.BookmarkColumns.URL };
String sel = Browser.BookmarkColumns.BOOKMARK + " = 0";
Cursor mCur = context.getContentResolver().query(Browser.BOOKMARKS_URI, proj, sel, null, Browser.BookmarkColumns.DATE + " DESC");
But it seems fom device to devie it logs only with one special browser:
s4 (4.2.2)=chrome
s5 (4.2.2)=chrome
htc one (4.2.2)=default browser
Samsung ace (4.1.2)=default browser
on what does it depend which browser logs it?
that depends if a browser logs to Android built-in Content Provider for the browser activity. Some browsers might, but not all of them do.
Usually the stock browser, the one that comes installed on the device, do. But there're no guarantees that others will.
I am using a QuickContactBadge. Now I get this messages on a Sony Xperia P. I developed the app on CyanogenMod and eveything was fine.
Unable to open content: content://com.android.contacts/contacts/939/photo
java.io.FileNotFoundException: content://com.android.contacts/contacts/939/photo
This is my code:
projection = new String[] {
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.PHOTO_URI };
contactCursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection, null, null, null);
...
thumbnail = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
...
quickContactBadge.setImageURI(Uri.parse(ThumbnailString));
My suggestion was that the Sony ROM doesn't deliver an valid PHOTO_URI but it looks legit.
The Solution is quit simple.
I discovered this Question which solves the Problem.
Where would I get started to create an app that would grab your Album Art based on Album or Artist of the mp3 from the internet (ie. via amazon, play.com, etc..)?
I would likely be using Eclipse.
Cusor cur = getContentResolver().query(Albums.EXTERNAL_CONTENT_URI, new String[] {Albums.ALBUM_ART}, Albums._ID + "=?", new String[] {albumid}, null);
Album Artist is still undocumented and not available before 2.3.3, I believe.
I've read related several questions here and can't find the answer to this: I have an Android 2.1 device (HTC Incredible). My app, however, must be compatible with early (pre SDK 5) devices, so I am using the deprecated format of filter URI:
Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(number));
Cursor C = context.getContentResolver().query(contactUri , null, null, null, null));
The number is of the form 15555551212. This fails to find the Contact, at least on my device. However, changing to the new (SDK 5 and later) ContactsContract format URI
Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Cursor C = context.getContentResolver().query(contactUri , null, null, null, null));
results in success. Originally, the corresponding number in the Contact was in the format +1 555 555 5555, but I changed it to exactly match the input number 15555555555 and the old format URI still fails. In both cases, the new format URI succeeds.
Does anyone have any thoughts as to why this is the case? I'm stumped!
That was it. The old API just won't do. Needing to be compatible with older devices, I used Reflection to laod and use the new API calls (ContactsContract) on API > 4.
I am making an application which requires me to list all the images available on the SD-Card of the phone.
I tried querying the ContentResolver way i.e.
Cursor image = getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, new String[]{Images.Media._ID,Images.Media.DATA,Images.Media.DISPLAY_NAME}, null, null, null);
but without any result.
Is there any way i can get the list or if that's not possible then is there any possible intent (e.g. PICK) by which I can allow the user to select a file and then access the path of the file the user selected??
//where contextObject is your activity
ContentResolver cr = contextObject.getContentResolver();
String[] columns = new String[] {
ImageColumns._ID,
ImageColumns.TITLE,
ImageColumns.DATA,
ImageColumns.MIME_TYPE,
ImageColumns.SIZE };
cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
columns, null, null, null);
My code is pretty much like yours (except broken down) and it works. You don't need to go about asking the Gallery Intent for stuff, it should work. My two guesses are:
1) Make sure your USB storage is not mounted, if it is you'll see no external images.
2) Maybe a permissions issue? Try adding GLOBAL_SEARCH permission to see if that helps at all.
You could use the gallery activity to select images, something like this:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);
in the callback for the activity the file uri will be in the intent parameter