android-contentresolver

Debugging slow ContentResolver query calls spending lots of time in “context switch”

元气小坏坏 提交于 2019-12-12 05:09:27
问题 Occasionally Android system calls, such as ContentResolver.query(...), can take 1000x times longer than normal, for example ~10 seconds for a single call that might normally complete in ~10 milliseconds. My question is how to identify cases like this, understand why it's happening and resolve the problem. The example below is retrieving the "user profile" on an Android system. On my Nexus 6 it normally takes ~10 milliseconds to do this. Older devices were similarly quick. Occasionally though

Getting full file name with extension

梦想与她 提交于 2019-12-12 04:45:59
问题 I have a method that should return the file name and file size returned from the contentResolver based on a selected file URI , however at times the file that was chosen has no extension. I am looking for a way to get the full file name with its extension or a way to determine the file type somehow. Below is my method I currently have //This is the intent which triggers the file choosing Intent fileIntent = new Intent( ); fileIntent.setType( "*/*" ); fileIntent.setAction( Intent.ACTION_GET

How to change type to image/*

孤者浪人 提交于 2019-12-12 03:37:23
问题 I have an error java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/* at android.app.WallpaperManager.getCropAndSetWallpaperIntent(WallpaperManager.java:792) at lv.revo.inspicfootballhd.MainActivity.onTouch(MainActivity.java:244) My code Uri uri = ResourceToUri(getApplicationContext(), imageArray[j]); File wallpaper_file = new File(uri.getPath()); Uri contentURI = getImageContentUri(getApplicationContext(),

Android: Accessing and querying properly using Raw Contact Id

半世苍凉 提交于 2019-12-11 22:54:19
问题 So my app is attempting to integrate a sync adapter to the android native contact manager. This is all running smoothly except once a contact is synced, I am unable to update it. Details on this particular problem can be found here: Android: Content resolver query returning 0 rows when it ought not to But I can sum it up simply by just saying my content resolver query is returning 0 values because I am querying the wrong URI, I believe. When I write the raw contact id to the phone, I do it

Android MediaStore get cursor position by comparing with TITLE_KEY

谁都会走 提交于 2019-12-11 22:53:31
问题 I am using MediaStore's media content and have a SearchView to filter the content displayed in a listfragment. I keep a reference to the cursor( mainCursor ) when the query string is null (which means all rows) When user searches, i get new cursor based on the query As per my understanding(I am very new to Cursor,DB & Contentprovider), the cursor will contain all the rows matching the query and the column to query is MediaStore.Audio.Media.TITLE , so i can see matching titles in list. public

How to get file path from the content uri for zip file?

这一生的挚爱 提交于 2019-12-11 17:14:14
问题 I am triggering an intent for selecting a zip file and in onActivityResult, it is providing me a content URI. For example :: (content://com.android.providers.downloads.documents/document/197). The file which is selected is from the download folder. Can any one explain, How to query the content resolver in order to get the file path? Thanks. Already tried code :- Cursor cursor = getActivity().getContentResolver() .query(contentUri, null, null, null, null); try { if (cursor != null && cursor

Android getting file path from content URI using contentResolver

白昼怎懂夜的黑 提交于 2019-12-11 14:17:20
问题 I'm trying to get the file path for a content URI. URL looks like this: content://com.android.providers.downloads.documents/document/31 The cursor object is not null but the cursor.getString(column_index) returns null. Column index is always 0. public static String getPath(Context context, Uri uri) throws URISyntaxException { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "data"}; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri,

Fastest method to insert words into UserDictionary

前提是你 提交于 2019-12-11 11:45:01
问题 I would like app to add several (2k) words to UserDictionary. I have experimented with ContentResolver().insert/bulk insert.... // array of words String[] words = getResources().getStringArray(R.array.word_array); Long start,end = null; start = System.currentTimeMillis(); int len = words.length; ContentValues[] mValueArray = new ContentValues[len]; ContentValues mNewValues = new ContentValues(); mNewValues.put(UserDictionary.Words.APP_ID, "com.my.example"); mNewValues.put(UserDictionary.Words

contentResolver.query(ContactsContract.Contacts.CONTENT_URI…) return 0 count Cursor if called after Intent.ACTION_INSERT

南笙酒味 提交于 2019-12-11 10:50:37
问题 I'm getting a weird behavior when testing my app on Huawei P8 . Everything works nice on emulators (android version 4, 5, 6, 7) and on ASUS (android 6) and Samsung Galaxy S2 (Android 4.2). The following steps work both on physical device and emulators. After calling contentResolver.query() I get a Cursor with all the contacts of my device. I open my app I call contentResolver.query(ContactsContract.Contacts.CONTENT_URI...); The following steps work everywhere except on my Huawei P8 ; with my

Getting null value while retrieving the CONTACT NAME from CONTACT EMAIL

萝らか妹 提交于 2019-12-11 10:47:09
问题 I want to retrieve the contact name from the contact email, so what I have done is as follows from https://stackoverflow.com/a/18064869/5738881. public static String readContacts(Context context, String email) { ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(email)); Cursor cursor = cr.query(uri, new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME}, null, null, null); if (cursor == null) { return