Android: How-To create an app that pulls Album Art? - android

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.

Related

android implicit intent edit failed to load image

This is my implicit intent to invoke image editing apps on the device:
startActivity(new Intent(Intent.ACTION_EDIT).setDataAndType(myUri,
getMimeType(myUri)).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION));
And this is how I getMimeType:
public String getMimeType(Uri uri) {
String mimeType = null;
if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
ContentResolver cr = getContentResolver();
mimeType = cr.getType(uri);
} else {
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri
.toString());
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
fileExtension.toLowerCase());
}
return mimeType;
}
For some apps it crashes to load:
On the app Sketch_Camera only an invisible page loads up and disables interaction with my app.
On the app AirBrush it loads the app but crashes with this message "Failed to load image".
Is it related to minimum sdk version as mine is 16?
I've tested this on minimum sdk version of 9 too and no change in result.
Is there anything else that I should add to this intent to work with all the apps?
I've tried putExtra too and it doesn't help:
.putExtra(Intent.ACTION_EDIT, myUri);
I've some gallery apps on my device and all of them launch Sketch_Camera and AirBrush without any problem.
What's happening here? I'm so confused after two days of struggling with this phenomena.
It's a file created from path of one media store file by querying MediaStore.Images.Media.EXTERNAL_CONTENT_URI
There is no guarantee that the other app has rights to this location, or even that your app has rights to this location. For example, the image could be on removable storage. Besides, the file Uri scheme is being banned for cross-app usage, anyway.
Use a content Uri instead. For example, in this sample app, I query MediaStore for videos. Given a Cursor named row positioned at a particular video, I generate the Uri for it via:
videoUri=
ContentUris.withAppendedId(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, row.getInt(row.getColumnIndex(MediaStore.Video.Media._ID)));
This Uri both works for my own purposes (e.g., hand to Picasso to get a thumbnail, hand to VideoView for playback) and for handing to third-party apps (e.g., ACTION_VIEW for playback).
Other than changing the base Uri to the one you queried against (MediaStore.Images.Media.EXTERNAL_CONTENT_URI), the same basic code should work for you.
Also, get rid of the flags from your Intent. Those are only for where the Intent points to your own ContentProvider, which is not the case in either your original code or with the Uri that you create from withAppendedId().

Android - Get latest photos taken

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.

browserhistory logged only with special browser

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.

Video thumbnails not refreshing

I am showing all available videos in a gridView on which are in SDCard by using following code.
String[] proj= {MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA,MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE };
videocursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
It is working fine... But if i made any changes to videos (i.e rename, delete) above code is not working. It is showing old content only, means not refreshing. How can i solve this problem
what should do is the following :
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
right after your code .
provides a way for applications to pass a newly created or downloaded media file to the media scanner service.

Looking up Contact from phone number - Old vs New URI: Old fails, New Succeeds?

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.

Categories

Resources