android-contentprovider

Dealing with (cross-process) exceptions in Android custom content provider

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 06:01:41
I have a custom content provider in my Android app that works reasonably well. I expect other apps to also access my content provider. I would like some clean way to communicate exceptions and errors, but as far as I can tell the Android content provider framework doesn't provide any way to propagate exceptions across processes. How should I indicate an exception state to my caller? Do I have to somehow encode it into my returned data and rely on clients to check for it? Is there any alternative? If encoding into the ordinary return data is it, what's the best way? (I can see a number of

Multiple rows insert with ContentProvider

会有一股神秘感。 提交于 2019-12-03 05:59:22
问题 I need to make insert of few rows in one transaction. Can I do it with ContentProvider? 回答1: On the client side, ContentResolver supports a bulkInsert() method. Those will not necessarily be processed in a single transaction by the ContentProvider , simply because there may not be any transactions performed by the ContentProvider . 回答2: I have implemented this in my app and here's the gist of the code that I use. In my content provider, I have overridden the applyBatch() method and it's a

Best practices for joining tables and notifying ContentObservers in Android ContentProvider

可紊 提交于 2019-12-03 05:58:44
问题 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

SyncAdapter periodicsync() not triggering

二次信任 提交于 2019-12-03 04:33:08
问题 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

Which thread runs ContentProvider?

烈酒焚心 提交于 2019-12-03 03:47:34
问题 If I call to a ContentProvider from a Activity, which thread is ContentProvider running in? E.g. What happens if the Activity is killed and a query is executing in the ContentProvider? Say that you have a slow network query f.ex. 回答1: If you mean the normal use case of using a ContentResolver to call a ContentProvider then here is what happens according to the best of my knowledge: I am assuming in this example that your ContentProvider lives in one process and your Activity in another

How to handle RESTful update of remote server with SyncAdapter

强颜欢笑 提交于 2019-12-03 03:47:12
问题 I've watched the Google I/O REST talk and read the slides: http://www.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html I'm still a bit unclear on how to nicely handle, say, an update error thrown by the remote server. I have implemented my own ContentProvider and SyncAdapter. Consider this scenario: Update a user's Contact Details via REST call: Request an update using a ContentResolver. My ContentProvider immediately updates the app's local Sqlite database and requests

Android: Get updated and deleted contact only

一世执手 提交于 2019-12-03 03:41:34
I am developing an application in which i am working on Android Contacts and not able to move ahead. In app the need of application is that the contact which is updated should send to server or the contact which is deleted should send to server for sync. I am using the contact service as: public class ContactService extends Service { private int mContactCount; Cursor cursor = null; static ContentResolver mContentResolver = null; // Content provider authority public static final String AUTHORITY = "com.android.contacts"; // Account typek public static final String ACCOUNT_TYPE = "com.example

Android Contacts provider get only phone contacts with all emails

微笑、不失礼 提交于 2019-12-03 03:13:44
问题 I need to get all phone contacts and their email address and photo uri: This is what am doing: private void getContacts() { ContentResolver cr = getContentResolver(); Cursor cur = cr.query(Contacts.CONTENT_URI, null, null, null, Contacts.DISPLAY_NAME); if (cur.getCount() > 0) { while (cur.moveToNext()) { // if // (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) // > 0) { Contact contact = new Contact(); String id = cur.getString(cur

How to implement complex queries using a Content Provider?

主宰稳场 提交于 2019-12-03 02:41:53
I am asking this because I am not quite sure of how to work with Android Content Providers. I have a subset of my database with 8 tables and I need to create complex queries to get some of the data. My content provider works fine with simple queries. For example, I have a table Person on my PersonModel.java class and I get the data using: String [] projection = {PersonModel.C_FIRST_NAME, PersonModel.C_LAST_NAME}; Cursor cursor = context.getContentResolver().query( MyProvider.CONTENT_URI_PERSONS, projection, null, null, null); and it works perfectly. On MyProvider I have a bunch of CONTENT_URI

Android camera intent FileUriExposedException for SDK >= 24

浪子不回头ぞ 提交于 2019-12-03 02:17:12
I use this code to get a picture from camera and put it on imageview: private void openCamera() { mMediaUri =getOutputMediaFileUri(MEDIA_TYPE_IMAGE); Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); photoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri); startActivityForResult(photoIntent, REQUEST_TAKE_PHOTO); // dialog.dismiss(); } private Uri getOutputMediaFileUri(int mediaTypeImage) { //check for external storage if(isExternalStorageAvaiable()) { File mediaStorageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); String fileName = ""; String fileType