android-contentresolver

Query using MockContentResolver leads to NullPointerException

烈酒焚心 提交于 2019-12-05 00:47:28
问题 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

get last Call on CallLog using a Service

血红的双手。 提交于 2019-12-04 18:24:23
I'm doing a program to send the CallLog to a Server, I created a Service that makes a poll of the telephone status with the following method. This method is called onCreate. private void pollForCallStatus() { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Log.d("Poll", Integer.toString(telephonyManager.getCallState())); switch (telephonyManager.getCallState()){ case TelephonyManager.CALL_STATE_RINGING: Log.d("CallService", "ringing"); break; case TelephonyManager.CALL_STATE_OFFHOOK: callStart(); break; case TelephonyManager.CALL_STATE_IDLE: callEnd(); break; } } }, 0

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

痴心易碎 提交于 2019-12-04 17:37:40
问题 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:

Unable to query ContentResolver to get downloaded file's name from my_downloads but works fine in all_downloads

扶醉桌前 提交于 2019-12-04 12:17:21
问题 My app is set up to activate once a file with extension .myappdata is opened. It accomplishes this through this intent-filter: <activity android:name="com.myapp.ExamineFileActivity"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="file" android:pathPattern=".*\\.myappdata" android:mimeType="*/*"/> <data android:scheme="content"

Android ContentResolver query sometimes not starting ContentProvider process

…衆ロ難τιáo~ 提交于 2019-12-04 09:05:43
I have been implementing my own custom content provider in an app A and want to query its database from a separate app B that calls ContentResolver.query(...) using the appropriate custom URI defined in A. All goes well when A has been running just before I launch B (thus A's process still running in the background). However when I kill A's process, then B fails to query A's database! I thought querying a content provider would automatically start its process so the data can be retrieved. Am I missing something? Some clarifications: I properly set up the content provider. There is no problem

getcontentresolver () is undefined for the type

。_饼干妹妹 提交于 2019-12-04 05:20:26
I try to get all contact names and number and i'm trying to use getContentResolver but i am getting the method get content resolver () is undefined for the type this error. How can i fix it ? Here is the code below : public class ContactManager { public ArrayList<Product> getContactNumber() { Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); while (phones.moveToNext()) { String name = phones .getString(phones .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String phoneNumber = phones .getString(phones

ContentResolver usage

允我心安 提交于 2019-12-04 04:20:37
I am new to andriod domain and is in learning phase. I got couple of queries: Do we have single ContentResolver object per app? Is it a singleton object? Who manages this object lifecycle? If it's singleton, how does it handles multiple request of querying a ContentProvider? Dharmendra From Alex Lockwood's Blog - http://www.androiddesignpatterns.com/2012/06/content-resolvers-and-content-providers.html What is the Content Resolver? The Content Resolver is the single, global instance in your application that provides access to your (and other applications') content providers. The Content

Android: getContext().getContentResolver() sometimes gets NullPointerException

ぃ、小莉子 提交于 2019-12-04 02:46:21
I want to ask why we get this annotation: Method invocation getContext.getContentResolver() may produce NullPointerException Why is it there and not in other parts of program Fragment/Activity? That approach has been used in tutorial made by Google - here is link for ContentProvider code https://github.com/udacity/Sunshine-Version-2/blob/sunshine_master/app/src/main/java/com/example/android/sunshine/app/data/WeatherProvider.java even if you create an aplication with just a blank activity and put that method in a newly created ContentProvider it is there. Should we use getContext()

How can I call getContentResolver in android?

我是研究僧i 提交于 2019-12-04 02:10:25
I'm writing a library class to encapsulate some of my logic in my first Android app. One of the functions which I want to encapsulate is a function which queries the address book. As such, it needs a ContentResolver . I'm trying to figure out how to keep the library functions black-boxed... that is, to avoid having each Activity pass in its own context to get a ContentResolver . Problem is I cannot for the life of me figure out how to get a ContentResolver from within my library function. I can't find an import that contains getContentResolver . Googling said to use getContext to get a Context

How to delete sim card contact in android

别说谁变了你拦得住时间么 提交于 2019-12-03 22:53:25
问题 below is my code for delete contact from phone Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)); Cursor cur = mContext.getContentResolver().query(contactUri, null, null, null, null); boolean flag = false; try { if (cur.moveToFirst()) { do { if (cur.getString( cur.getColumnIndex(PhoneLookup.DISPLAY_NAME)) .equalsIgnoreCase(name)) { String lookupKey = cur .getString(cur .getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); Uri uri = Uri.withAppendedPath