I am creating my own android app widget to display browser bookmarks. & i need 2 show the thumbnail image of the bookmarks in my widget.
However the Browser.BookmarkColumns doesnt expose the "thumbnail" data.
any idea on how to get the thumbnail image ?
thanx in advance
It does expose the fav icon of the website. But its available in the database if that bookmark url was successfully visited at least once. Also when accessing the internal Android databases use the managedQuery() method.
Here is a snippet for accessing the fav icon from db.
Cursor mCur = managedQuery(android.provider.Browser.BOOKMARKS_URI,
projection, null, null, null);
mCur.moveToFirst();
int titleIdx = mCur.getColumnIndex(Browser.BookmarkColumns.TITLE);
int urlIdx = mCur.getColumnIndex(Browser.BookmarkColumns.URL);
int urlIdx = mCur.getColumnIndex(Browser.BookmarkColumns.FAVICON);
Related
Using this method of audio file retrieval from Android's external storage
Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
can I actually find a resonable way to fetch a genre of the given song? MediaStore class seems to provide everything else - from song's title to its composer info - except for the genre field. Should I use MediaMetadataRetriever then? If so, how drastically can creating a MediaMetadataRetriever instance for every song on a device reduce app's performance?
Maybe there are some better ways to retrieve all audio files from both external and internal storages in android?
As mentioned at Developer's Site,
You can fetch the Genres of the Audio file using MediaStore.Audio.Genres
Sample Code :
private static String[] genresProj = {
MediaStore.Audio.Genres.NAME,
MediaStore.Audio.Genres._ID
};
int idIndex = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
while (cursor.moveToNext()){
int id = Integer.parseInt(mediaCursor.getString(idIndex));
Uri uri = MediaStore.Audio.Genres.getContentUriForAudioId("external", id );
genresCursor = context.getContentResolver().query(uri,
genresProj , null, null, null);
int genreIndex = genresCursor.getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME);
while (genresCursor.moveToNext()) {
Log.d(TAG, "Genre = " +genresCursor.getString(genreIndex));
}
}
}
To fetch other details of the Audio file, please check here .
I tried to read the complete profile information such a (Full name, phone, adresse, mail .... ).
I have searched everywhere for a good example code. I tried many ways (Uri => Cursor) to access the Profile.
At this time I can fetch just the Full name (of the Profile contact), nothing more.
I can fetch data of other contacts using an Intent, sending to the Contacts app, BUT I CAN'T READ THE PROFILE CONTACT (JUST FULL NAME).
I have added the READ_PROFILE permission in the manifest file.
With the following code I get the Full Name (I can also access first and last name separately ):
Uri uriProfile = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
Cursor cursorProfile = this.getContentResolver().query(uriProfile,
null, null, null, null);
String projection = Profile.DISPLAY_NAME;
String profileName = cursorProfile.getString(cursorProfile.getColumnIndex(projection);
But when I use this the following projection to get Phone Number, it returns an error and the app stops working:
String projection = ContactsContract.CommonDataKinds.Phone.NUMBER
I found a solution using this code:
Get an URI Profile
Crate a cursor pointing to the URI content with null projection. Because for the profile, data are saved differently than a normal contact.
Point the cursor to the wanted data using MIMETYPE.
Uri uriProfile = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
Cursor cursorProfile = getApplicationContext().getContentResolver().query(uriProfile,
null, null, null, null);
String cursorProfile_MIMIETYPE = cursorProfile.getString(cursorProfile.getColumnIndex("MIMETYPE"));
I am working upon a music player app for android. I'm trying to use Picasso (an external library) to load the album arts efficiently. But the album arts are not getting displayed. There's no error in the code and the project compiles properly but the images are not getting displayed.
To do this, I'm fetching the album art Uri from "MediaStore.Audio.AlbumColumns.ALBUM_ART". Then I use this in my list adapter's getView() method:
Picasso.with(context).load(Uri.parse(album_art_uri)).into(myImageView);
I don't know what's wrong here? Please help me figure it out.
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null,
null);
int album_id = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ALBUM_ID);
cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
MediaStore.Audio.Albums._ID+ "=?",
new String[] {musicCursor.getString(album_id)},
null);
if (cursor.moveToFirst()) {
thisAlbumArt = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
}
Then load with picasso as follows in your getView().It worked for me but it is slow
Picasso.with(mContext)
.load(Uri.parse("file://"+thisAlbumArt))
.resize(220,220)
.noFade().centerCrop()
.error(R.drawable.music)
.placeholder(R.drawable.blank_img)
.into(yourImageView);
reference link:
How can I display Album Art using MediaStore.Audio.Albums.ALBUM_ART?
I've been thinking of ways to make this work, and I just dont get it.
I have several HTML files that are viewed using webView, I want to create a bookmark button on this WebView page.
If I create a DB with a table and three columns - containing the _id, the Title, and the URL, and populate it with the Titles and the URLs(from assets folder) and give each an IDs. When the "Add to Bookmark" button is clicked in the WebView activity, can it populate a ListView in the Favorites activity, and when the title is clicked, it locates the URL that corresponds in the SQLDB and then open it.
I have googled on SQLDB, but most of the tutorials do not make use of an already stored data in DB.
Thank you.
Alright use this code :
// Saving the bookmark via ContentProvider
final ContentValues bookmarkValues = new ContentValues();
bookmarkValues.put(Browser.BookmarkColumns.TITLE, title);
bookmarkValues.put(Browser.BookmarkColumns.URL, url);
bookmarkValues.put(Browser.BookmarkColumns.BOOKMARK, 1);
final Uri newBookmark = getContentResolver().insert(Browser.BOOKMARKS_URI, bookmarkValues);
// Retrieving
Cursor cursor = getContentResolver().query(Browser.BOOKMARKS_URI,
null, null, null, Browser.BookmarkColumns.CREATED);
cursor.moveToFirst();
final String stitle = cursor.getString(cursor.getColumnIndex("title"));
final String surl = cursor.getString(cursor.getColumnIndex("url"));
I have a small FileExplorer in my app and i want him to start in the folder, which is currently used by the defautl camera. Is there a way to get this path?
I tryed:
Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES).getAbsolutePath());
But this do not returns "/mnt/sdcard/Pictures" and my Camera is storing in "mnt/sdcard/ext_sd/DCIM/100MEDIA/"
PS:
I do know how to start the camera with a specific folder for storing the pictures, that's not what i'm searching for,
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 = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,projection, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
if(cursor != null){
cursor.moveToFirst();
// you will find the last taken picture here
// according to Bojan Radivojevic Bomber comment do not close the cursor (he is right ^^)
//cursor.close();
}