android-contentresolver

registerContentObserver() on raw SQLite Cursor

南笙酒味 提交于 2019-11-30 00:24:33
All of the examples I've seen of using registerContentObserver() do so through a ContentProvider interface. But Cursor has a registerContentObserver() call, so I figured maybe the Android folks have put together some deep magic that would allow for getting updates on a SQLite cursor when one of the rows from an active result set changed. Either I'm doing it wrong, or there is no such magic. Here's the code I'm working with, the expectation being that when I click on the button to update the value in row #1 I would get an onChange() callback. Any ideas? public class MainActivity extends

ContentResolver doesn't contain just created image in an immediate query after creation of file

删除回忆录丶 提交于 2019-11-29 23:54:40
问题 I'm using this code to copy an image using documentFile.createFile() private void newcopyFile(File fileInput, String outputParentPath, String mimeType, String newFileName) { DocumentFile documentFileGoal = DocumentFile.fromTreeUri(this, treeUri); String[] parts = outputParentPath.split("\\/"); for (int i = 3; i < parts.length; i++) { if (documentFileGoal != null) { documentFileGoal = documentFileGoal.findFile(parts[i]); } } if (documentFileGoal == null) { Toast.makeText(MainActivity.this,

Set raw resource as ringtone in Android

╄→尐↘猪︶ㄣ 提交于 2019-11-29 22:46:08
问题 In my android application, I want to set audio file from my raw folder as a ringtone. For that i wrote below code, but its not working. Please help me to solve this issue. Thank you. Code : String name =best_song_ever.mp3; File newSoundFile = new File("/sdcard/media/ringtone", "myringtone.mp3"); Uri mUri = Uri.parse("android.resource://" + context.getPackageName() + "/raw/" + name); ContentResolver mCr = context.getContentResolver(); AssetFileDescriptor soundFile; try { soundFile = mCr

Android Create Playlist

佐手、 提交于 2019-11-29 20:42:12
Anyone know how to add playlists to Android in code? I kind of get that I have to insert it into the content resolver but do I have to just put the song id in or do I have to put all of the song's data in? I have been looking for sample code but haven't found any yet. EDIT: Found an answer here is how I do it: public static void addToPlaylist(ContentResolver resolver, int audioId) { String[] cols = new String[] { "count(*)" }; Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", YOUR_PLAYLIST_ID); Cursor cur = resolver.query(uri, cols, null, null, null); cur.moveToFirst();

SMS Messages of a particular number not showing up on other devices Android

做~自己de王妃 提交于 2019-11-29 18:49:32
I am using the Telephony.Sms library to load in received and sent sms messages for the app I am working on. When I set the query selection to null (the third item in the query), it will show all the sent and received sms messages on the different types of phones I have been testing on. Cursor c = cr.query(Telephony.Sms.CONTENT_URI, null, null, null, null); But when I set it to a particular number, on the Samsung S9 phone running on API 27 it is not showing any sms messages. On the Nexus runnning on API 23, it will show the received messages but not the sent messages in the listview. On the

Display the Contacts in sorting order ContactsContract.Contacts of Content Resolver

匆匆过客 提交于 2019-11-29 11:48:22
问题 My intention is to display the contacts in sorting order using content resolver in android. For that i am writing: Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+ " = ?", new String[] { id }, null); It needs that the last parameter in query method should not be null for sorting the elements by Name . Which part of code I have to replace the null parameter to achieve sorting by name ? Or please help me querying

Edit name/phone number of contact programmatically

喜欢而已 提交于 2019-11-29 10:07:26
I am trying to modify displayed name of a contact programmatically: try { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) .withSelection(ContactsContract.CommonDataKinds.Phone._ID + " = ?", new String[] {contact_id}) .withValue(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "anything") .build()); ContentProviderResult[] result = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); } catch (Exception e) { Log.w("UpdateContact", e.getMessage()+""); for(StackTraceElement ste : e

Android: Getting image bitmap from third party app (e.g. WhatsApp) via content:// URI

自作多情 提交于 2019-11-29 07:23:05
I am trying to get image from third party app (e.g WhatsApp) to my app (being tested on Marshmallow). When I do "share image" from WhatsApp and share it with my app, I get URI something like this: content://com.whatsapp.provider.media/item/61025 But in my app when I call getContentResolver().openInputStream(uri) or getContentResolver().openFileDescriptor(uri, "r") with above URI, it crashes with exception: java.lang.SecurityException: Permission Denial: opening provider com.whatsapp.MediaProvider from ProcessRecord{a4b804a 30321:com.myapp/u0a145} (pid=30321, uid=10145) that is not exported

ContentResolver - how to get file name from Uri

血红的双手。 提交于 2019-11-29 07:05:53
问题 I call startActivityForResult with Intent ACTION_GET_CONTENT. Some app returns me data with this Uri: content://media/external/images/media/18122 I don't know if it is image or video or some custom content. How do I use ContentResolver to get the actual file name or content title from this Uri? 回答1: You can get file name from this code, or any other field by modifying the projection String[] projection = {MediaStore.MediaColumns.DATA}; ContentResolver cr = getApplicationContext()

Android Create Playlist

孤街浪徒 提交于 2019-11-28 16:22:27
问题 Anyone know how to add playlists to Android in code? I kind of get that I have to insert it into the content resolver but do I have to just put the song id in or do I have to put all of the song's data in? I have been looking for sample code but haven't found any yet. EDIT: Found an answer here is how I do it: public static void addToPlaylist(ContentResolver resolver, int audioId) { String[] cols = new String[] { "count(*)" }; Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(