contentobserver

Android ContentProvider+ContentObserver

这一生的挚爱 提交于 2020-03-02 07:41:09
说明:文章仅供本人学习记录所用。 1.理解含义: ContentProvider: 内容提供者,将数据以表的形式进行操作。主要 实现应用程序间数据共享,操作 系统本地数据(包括短 信、音频、视屏、数据库)。 ContentObserver:内容观察者,监听数据变化。 2.使用方法: ContentProvider: 1)步骤:新建MyProvider类继承ContentProvider类;注册URI;重写方法(onCreate、query、bulkInsert、insert、 delete、update);在AndroidManifest.xml中配置provider; 2)代码: public class MyProvider extends ContentProvider { private static UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH); private static final int INSERT = 1; private static final int UPDATE = 2; private static final int DELETE = 3; private static final int QUERY = 4; private static final int INSERTS =

get SMS number at outgoing time by contentObserver

蓝咒 提交于 2020-02-20 13:00:46
问题 this is the code that i have try to get sms number when i send sms from default emulator, but it not work. just check out and tell me about that Thanx package com.SMSOberver5; import android.app.Activity; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.widget.Toast; public class SMSOberver5 extends Activity { /** Called when the activity is first created. */ Handler handler =

Catch sent SMS (Android 2.2)

戏子无情 提交于 2020-01-23 18:25:28
问题 I know that there are a few Questions here on SO relating to this, but none of them helped me to get this working - capture SMS that being sent. I am using Android 2.2 (FROYO) on a Samsung phone (if that matters somehow). I've searched a lot for this on Stackoverflow and realized that I need ContentObserver for my request. I'm using Service instead of Activity, so I've registered that ContentObserver in my Service class, and it looks like this: public class SMSSending extends Service {

How to observe changes in database in order to update LiveData

半世苍凉 提交于 2020-01-13 13:36:09
问题 I am migrating an app from a LoaderManager with Callbacks to an implementation using ViewModel and LiveData . I would like to keep using the existing SQLiteDatabase . The main implementation works OK. The Activity instantiates the ViewModel and creates an Observer which updates the View if it observes changes in the MutableLiveData that lives in the ViewModel . The ViewModel gets it data (cursor) from the SQLiteDatabase through a query using a ContentProvider . But I have other activities

Android notify when phone book is updated(Content Observer)

不羁岁月 提交于 2020-01-10 18:44:05
问题 I want to get a notification on my phone if there is any change in the contact database(add,delete).Right now i am using ContentObserver to get notified.Following is my code.Problem is that i able not able to know which contact is changed.Can anyone help??? public class ContentObserverActivity extends Activity { Button registerbutton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); registerbutton=(Button

ContentObserver per row implementation

白昼怎懂夜的黑 提交于 2020-01-06 15:19:06
问题 After "observing" about ContentObserver I noticed that OnChange before API 16 not passing any parameters, so I decided to implement it to each row on my project (the project is downloading url's with the build-in DownloadManager) for each row I'm creating a new ContentObserver : Uri downloadsContentUri = Uri.parse("content://downloads/my_downloads/downloads/" + appDownloadId); DownloadsObserver downloadsObserver = new DownloadsObserver(downloadId, new Handler()); getContentResolver()

contentobserver works only for insert and delete but not for an update

亡梦爱人 提交于 2020-01-06 12:54:16
问题 I am developing an app that notify the user when any SMS marked as read even if the app isn't running I simply created a contentobserver and I registered it in a service the problem is that the contentobserver runs if the new SMS inserted or deleted but when the SMS marked as read ( Update operation) it doesn't work here is my service code public class Smssendservice extends Service { private static Timer timer = new Timer(); private Context ctx; public IBinder onBind(Intent arg0) { return

Content Observer changes

浪尽此生 提交于 2020-01-03 20:09:12
问题 If I register a content observer on say the calendar database is there a way to get exactly what changed in the database when an event gets edited? 回答1: Can't be done...Diane Hackborn claims it's intentional. You'll have to requery or use a sync adapter. 回答2: Make use of shared preferences and content providers along with content observer. When I read the DB, I know that I have read all the entries until the time stored in shared preferences. So each time I read DB, I need to check for all

FIleObserver and ContentObserver not working in Android Marshmallow

老子叫甜甜 提交于 2019-12-30 08:23:11
问题 I have issue with both FIleObserver and ContentObserver not working in Android Marshmallow. I am using this thing for detecting changes that happening inside a folder. I set run time permissions for marshmallow. But after that also it shows no events. It works perfectly in other versions. Please help me to solve this problem. First I tried Content Resolver inside Service for detect folder changes in background. public class TestService extends Service { @Override public void onCreate() {

How to make ContentObserver work without having application opened?

こ雲淡風輕ζ 提交于 2019-12-25 02:09:46
问题 I need to have my application listen for changes in addressbook in Android. I have read that it can be done using ContentObserver and listening for changes in ContactsContract.Contacts . It seems the lifecycle of the ContentObserver ends when the application is closed. How do I make the ContentObserver work even if the application wasn't opened? 回答1: How do I make the ContentObserver work even if the application wasn't opened? That is not possible. The point behind a ContentObserver is to be