android-contentprovider

SQLite data to a RecyclerView

天涯浪子 提交于 2019-12-04 02:46:38
The app has data in a SQLite database. The UI is primarily a RecyclerView. The question is how to best to transfer data from the database into the UI, whilst keeping off the main thread? I originally planned to use a CursorLoader, ContentProvider, and RecyclerView. But reading around it looks like RecyclerView has no out-of-the-box support for Cursor-supplied data. Dang. That then leaves me with a few other options... AsyncTask to load the data, put it into model objects, and pass into the RecyclerView Adapter. Aside from being ugly, it isn't config-change friendly. A custom Loader that loads

How to get bitmap providing a URI, java.io.FileNotFoundException: No content provider: /sdcard/Hello/1310610722879.jpg

喜你入骨 提交于 2019-12-04 02:32:28
I've read the example to do this: protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { Uri imageUri = data.getData(); Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri); } } But i get java.io.FileNotFoundException: No content provider: /sdcard/Hello/1310610722879.jpg My code is here: Uri uri1 = Uri.parse(Config.getPhotoPath(this)); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri1); attachButton.setImageBitmap

What the appropriate replacer of deprecated “ managedQuery”?

元气小坏坏 提交于 2019-12-04 02:18:04
Android documentation said: This method was deprecated in API level 11. This is code: class GridViewActivity_ extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gridview); GridView gv = (GridView)findViewById(R.id.gridview); Cursor c = managedQuery(Contacts.CONTENT_URI, null, null, null, Contacts.DISPLAY_NAME); String[] cols = new String[]{Contacts.DISPLAY_NAME}; int[] views = new int[] {android.R.id.text1}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1,

What is the purpose of an Android projection map in a content provider?

こ雲淡風輕ζ 提交于 2019-12-04 02:09:30
I am looking at the Android notepad application sample code in <path_to_SDK>/samples/android-16/NotePad/src/com/example/android/notepad . I was wondering if anyone could explain to me why the following code is needed in NotepadProvider.java ? // Creates a new projection map instance. The map returns a column name // given a string. The two are usually equal. sNotesProjectionMap = new HashMap<String, String>(); // Maps the string "_ID" to the column name "_ID" sNotesProjectionMap.put(NotePad.Notes._ID, NotePad.Notes._ID); // Maps "title" to "title" sNotesProjectionMap.put(NotePad.Notes.COLUMN

AccountManager does not add custom account in Android N preview

ぃ、小莉子 提交于 2019-12-04 00:42:40
I have implemented a sync adapter in my app which requires an account to be added in the device account settings. I followed the same approach given in the Android docs. It works fine till Marshmallow and I can see my account listed in the device accounts. But in Android N preview, account does not add to the device accounts. AccountManager's addAccountExplicitly() method always returns false. Has anyone faced this problem? Not sure if this is the same issue, but there's an issue with AccountManager on the current version of the Android N image. Basically, if you: Add an account to

Search Suggestion results displayed as blank/no text

痴心易碎 提交于 2019-12-04 00:18:48
I have included a Search Dialog in my Activity which works fine. However adding Search Suggestions gives me a little problem: The search suggestion entries are "empty". I can see my content provider gets called (query(..)) and I return a MatrixCursor with several rows. The suggestions list also shows with (clickable) entries -- but are all blank. Blank as if the string I returned for SUGGEST_COLUMN_TEXT_1 and SUGGEST_COLUMN_TEXT_2 where an empty string. The columns I use in the MatrixCursor are: String[] columnNames = {"_ID", "SUGGEST_COLUMN_TEXT_1", "SUGGEST_COLUMN_TEXT_2", "SUGGEST_COLUMN

Class structure for a ContentProvider having multiple sub tables

江枫思渺然 提交于 2019-12-03 22:19:38
The ContentProvider doc says to make ONE entry in the AndroidManifest for your ContentProvider class. If your class supports multiple sub-tables then there must be one CONTENT_URI constant declared for each. How? You can't do that unless you sub-class for each sub-table. Why not just have multiple providers? Do you implement the sub-table providers as descendants? With multiple sub-tables, there is still only ONE ContentProvider class? As you can see, I'm confused by the documentation. It reads: Define a public static final Uri named CONTENT_URI. This is the string that represents the full

ContentObserver should call if and only if ContactsContract.Contacts.CONTENT_URI changes

≯℡__Kan透↙ 提交于 2019-12-03 18:02:04
问题 As my application uses content from android.provider.ContactsContract.Data (API > 11) and ContactsContract.Contacts.CONTENT_URI (API < 11) to populate Contacts . I've tried to registerContentObserver() against these provider. But it calls my ContentObserver even if I tries to Call a person from device as soon as I put the call. It does trigger my ContentObserver which is not useful for me as there's no Content Change in Contacts Provider . Root Cause: Seems like LAST_TIME_CONTACTED or

Fetch Genre name list which have songs in it

主宰稳场 提交于 2019-12-03 15:41:29
I am fetching Genre list from media content Provider of android using CursorLoder class. below is my cursor query to fetch the list of Genre. public Loader<Cursor> onCreateLoader(int id, Bundle args) { // currently filtering. Uri baseUri; baseUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI; String[] STAR = { "*" }; return new CursorLoader(getActivity(), baseUri, STAR, null, null, null ); } Now, i got all the genre list from the media content provider but the problem with the data i got. I also got the genre name which is created before but right now i don't have song in it. I only want the

Query using MockContentResolver leads to NullPointerException

ぐ巨炮叔叔 提交于 2019-12-03 15:28:55
We have a JUnit test class which extends ActivityInstrumentationTestCase2<CommentActivity> . The test (and the class we're testing) use CommentContentProvider , which extends ContentProvider , to access the SQLite database, and we're getting a NullPointerException [full stack trace below] when running a query on the provider. We instantiate a MockContentResolver as shown: MockContentResolver mResolver; public void setUp() { super.setUp(); CommentContentProvider ccp = new CommentContentProvider(); mResolver = new MockContentResolver(); mResolver.addProvider(CommentContentProvider.AUTHORITY, ccp