android-contentprovider

Difference between ContentObserver and DatasetObserver?

霸气de小男生 提交于 2019-12-03 01:41:14
问题 What is difference between ContentObserver and DatasetObserver ? When one or another should be used? I get Cursor with single row. I want to be notified about data changes - eg. when row is updated. Which observer class should I register? 回答1: If you are using a ContentProvider (via ContentResolver or Activity.managedQuery() ) to get your data, simply attach a ContentObserver to your Cursor . The code in onChange() will be called whenever the ContentResolver broadcasts a notification for the

How to use bulkInsert() function in android?

橙三吉。 提交于 2019-12-03 00:13:58
I want only a single notification after all the bulk insertion is done into database. Please provide an example to use bulkInsert() function. I cannot find a proper example on internet. Please Help!!!! This is bulkInsert using ContentProvider. public int bulkInsert(Uri uri, ContentValues[] values){ int numInserted = 0; String table; int uriType = sURIMatcher.match(uri); switch (uriType) { case PEOPLE: table = TABLE_PEOPLE; break; } SQLiteDatabase sqlDB = database.getWritableDatabase(); sqlDB.beginTransaction(); try { for (ContentValues cv : values) { long newID = sqlDB.insertOrThrow(table,

android: Implement app search suggestion based on server response

江枫思渺然 提交于 2019-12-02 23:46:10
I need to build a search functionality in my android app which relies on json response from the server. The users will enter the search query in a searchview located in the actionbar. Based on what the user types a query will be made to the server and the server returned response should appear as drop down suggestion. How should I go about it . Based on the docs i have read I need to implement a content provider. What would be neatest way of implementing app search ? See the below code I have implemented for EditText.You can also do something like this: private ArrayList<JSONObject>

How to address multiple content providers?

梦想与她 提交于 2019-12-02 22:51:59
I created two content providers that work on two different tables of the same SQLite database. They share a single instance of SQLiteOpenHelper as described in the post of Ali Serghini . Each content provider is registered in AndroidManifest.xml as follows. <provider android:name=".contentprovider.PostsContentProvider" android:authorities="com.example.myapp.provider" android:exported="false" android:multiprocess="true" > </provider> <provider android:name=".contentprovider.CommentsContentProvider" android:authorities="com.example.myapp.provider" android:exported="false" android:multiprocess=

Android private content provider?

和自甴很熟 提交于 2019-12-02 21:38:26
I am developing an application that involves some sensitive user information. I retrieve this information via a private web API. I am trying to determine the best way to get this data into my app. Right now I'm exploring creating a content provider that can do so; my hesitation is in making it secure. I want this data to be usable only by my application. Ideally, no other apps would even know it exists. Do you have any pointers or advice on how to do this effectively and securely? Any info on content providers who's data source is a remote OAuth'd API? Thanks! Edit: I say content provider, but

Querying Google Play Music database in Android

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 20:57:00
I am trying to query for the playlists created by "Google Play Music" app but haven't been able to do so. I created a playlist using locally stored content. I used the following code to query: Cursor c = managedQuery(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME }, null, null, null); This works fine for Winamp but not for Google Play Music. In fact, Winamp doesn't display the playlists created with Google Play Music. However, Google Play Music displays the playlists created with Winamp. My guess is that Google

Custom Search for contacts in android

前提是你 提交于 2019-12-02 20:02:41
问题 I want to custom search in contacts in android. For example, i want contacts that each contact number end with 555 so how can i do that? 回答1: Get all contacts and search manually using code. ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); String phone = null; if (cur.getCount() > 0) { while (cur.moveToNext()) { String id = cur.getString(cur .getColumnIndex(ContactsContract.Contacts._ID)); if (Integer .parseInt

Best practices for joining tables and notifying ContentObservers in Android ContentProvider

喜你入骨 提交于 2019-12-02 19:20:24
I have a ContentProvider which handles all the data insertion and retrieval related to my application, I'm following the pattern suggested by Virgil Dobjanschi on Google I/O. I am using the first pattern. My problem is that I have a logical entity that was represented by multiple tables in the database. For example, I have an Articles table and an ArticleExtras table. Articles represents the article itself, while ArticleExtras represents addtional information about certain Article, like number of comments. I used CursorAdapter in the UI to display the Article title and the number of comments

SyncAdapter periodicsync() not triggering

一曲冷凌霜 提交于 2019-12-02 17:44:14
I'm trying ty figure out how the syncAdapter works, I used the sampleSync Adapter as an example/starting point and I based my first test on it. The only difference is that I'm not working with the default contacts provider, but that I need one of my own. This method is kinda the same as in the sampleSyncAdapter demo (in AccountAuthenticatorActivity), i've just added the periodic sync. public void finishLogin(String authToken) { Log.i(TAG, "finishLogin()"); final Account account = new Account(mUsername, "be.company.syncAdapterTest"); if(mRequestNewAccount) { mAccountManager.addAccountExplicitly

How to transfer files between Android applications running on the same device?

て烟熏妆下的殇ゞ 提交于 2019-12-02 17:33:42
I am writing an Android application that interfaces with a RESTful service. This web service essentially fronts a file system, and provides metadata as well CRUD access to the files. My application retrieves the metadata, and exposes it to 3rd party apps through a ContentProvider . I need to add the ability for 3rd party applications, running on the same device as my app, to CRUD the actual files by making requests to/from my app (not directly with the server). This means they need to either send or receive the contents of the files (which are typically XML or images) through my app. I have