android-contentresolver

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

How to listen new photos in android?

左心房为你撑大大i 提交于 2019-12-03 15:08:34
I need to listen to new images that comes from any source like downloading images, capture new images, other apps download images..etc Is there any listener that will trigger event whenever new photos is added to gallery? I have been searching for two days. I could not get anything solid. I read about FileObserver , will that help? new photos arrives to gallery means it has been added to the MediaStore . First of all, FileOberver is a memory-killer approach. Consider a high volume of files. Rather ContentObserver seems a far better approach. getContentResolver().registerContentObserver(android

How to access sms time which I have received in inbox?

走远了吗. 提交于 2019-12-03 13:35:11
I am able to read message from the inbox from this:-- Uri uriSMSURI = Uri.parse("content://sms/inbox"); Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null); i access date from this:- date = cur.getString(cur.getColumnIndexOrThrow("date")); But now problem is that it gives current time not Message Time from inbox. Sorry for Bad editing & any idea will be appreciated. Thanks in Advance! Use this code: ContentResolver contentResolver = getContentResolver(); Cursor cursor = contentResolver.query( Uri.parse( "content://sms/inbox" ), null, null, null, null); cursor.moveToFirst

How to load a Picasa image from URI?

余生颓废 提交于 2019-12-03 12:01:01
问题 I'm using ACTION_PICK intent to select an image from gallery. Some albums like "Posts" , "Profile Photos" , etc are marked with Picasa icon. For images from such albums I get a URI similar to this: content://com.google.android.gallery3d.provider/picasa/item/5769844615871490082 I can load an image from this URI using ContentResolver and BitmapFactory with no problem: final InputStream ist = context.getContentResolver().openInputStream(intent.getData()); final Bitmap bitmap = BitmapFactory

Android get sms from inbox, optimized way to read all messages and group them

不想你离开。 提交于 2019-12-03 11:04:12
Hi am implementing a SMS App, now am able to retrieve all messages with their respective contact info like display name, photo uri.. and am displaying them in a custom list where on item click takes you to respective discussion. Here my issues is the time taking to sync all these messages, I need to optimize this time. Each time i send a new message in the discussion view and go back to recent chats i need to only update the particular item, not the whole list. Here's my code: ReadSMS.java: public class ReadSMS { ArrayList<HashMap<Contact, ArrayList<OneComment>>> recentChats; Application

How do I restrict access to my ContentProvider to only my apps?

蹲街弑〆低调 提交于 2019-12-03 08:48:14
I want to export a ContentProvider for use by another one of MY apps. How do I prevent other apps from accessing it? If I use an android:permission attribute, can't 3rd party apps just apply that permission to their app? I really need to lock down access to my apps only. Thanks in advance... If I use an android:permission attribute, can't 3rd party apps just apply that permission to their app? Well, you can use a signature -level custom permission ( android:protectionLevel="signature" ). Then, the app holding the permission and the app defending itself with the permission have to be signed by

SyncAdapter running animation - how to know if SyncAdapter is actively synchronizing

旧城冷巷雨未停 提交于 2019-12-03 06:10:07
问题 I want to show a ProgressBar in the ActionBar while my SyncAdapter is actively synchronizing content to and from the web. I have tried using the SyncStatusObserver together with ContentProvider.addStatusChangeListener. However, I cannot check if a SyncAdapter is actively running. I can only check: SyncAdapter is pending using ContentResolver.isSyncPending SyncAdapter is pending OR actively working using ContentResolver.isSyncActive These flags can be combined: !isSyncPending && isSyncActive

How does getContentResolver() work?

北战南征 提交于 2019-12-03 04:43:23
问题 I watched a course about ContentProvider on the Internet demonstrating how to define and use a ContentProvider . I was confused about using the method named getContentResolver() . What does this method return? My ContentProvider is not instanced and the code just writes that getContentProvider().query() . I don't understand how ContentProvider works. 回答1: It returns Content Resolver. What is the Content Resolver? The Content Resolver is the single, global instance in your application that

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 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=