更快最快的方式来启动应用程序时获取新的短信 – Android

更快最快的方式来启动应用程序时获取新的短信 – Android,第1张

概述我有一个sqlite数据库,其中包含用户的所有短信,但是当你启动应用程序时,如果用户决定在其间使用不同的短信应用程序,我需要获取我可能没有的所有短信. 我正在寻找将我的数据库与基本android内容提供程序同步的最佳方法. 目前我为每个短信执行插入或忽略,如下所示: insert or ignore into sms (smsID, smsCONID, smsMSG, smsNUM, smsREA 我有一个sqlite数据库,其中包含用户的所有短信,但是当你启动应用程序时,如果用户决定在其间使用不同的短信应用程序,我需要获取我可能没有的所有短信.

我正在寻找将我的数据库与基本android内容提供程序同步的最佳方法.

目前我为每个短信执行插入或忽略,如下所示:

insert or ignore into sms (smsID,smsCONID,smsMSG,smsNUM,smsREAD,smsTIMESTAMP,smsTYPE,smsSHORTMSG) values (?,?,?);

我加载收件箱并在我的启动画面活动中以单独的asynctasks发送消息
这需要大约10s左右.

我的doInBackground:

@OverrIDe    protected VoID doInBackground(VoID... arg0) {        int thread_ID = 0;        int _ID = 0;        int read;        String number;        boolean first = true;        String msg;        long timestamp;        /**         * RECUPERATION DES MESSAGES RECUS         */        // PREPARE CURSOR        cursorInBox.movetoFirst();        while (cursorInBox.movetoNext()) {            if(first){                cursorInBox.movetoFirst();                first = false;            }            // RECUPERE THREAD_ID + ID_SMS + NUMERO DU CONTACT            thread_ID = cursorInBox.getInt(cursorInBox.getColumnIndexOrThrow("thread_ID"));            _ID = cursorInBox.getInt(cursorInBox.getColumnIndexOrThrow("_ID"));            number = cursorInBox.getString(cursorInBox.getColumnIndexOrThrow("address"));            msg = cursorInBox.getString(cursorInBox.getColumnIndexOrThrow("body"));            read = cursorInBox.getInt(cursorInBox.getColumnIndexOrThrow("read"));            timestamp = cursorInBox.getLong(cursorInBox.getColumnIndexOrThrow("date"));            // CREER LE SMS            dataManip.insert(_ID,thread_ID,msg,number,read,timestamp,"received",ContactsFactory.getMessageShort(msg));            i++;             publishProgress(i);        }          Log.d(TAG,"LoadActivity - InBox Loaded");        return null;    }

推动的想法?

解决方法 如何在单独的服务中收听 registering a ContentObserver以收听AndroID SMS提供商的更改?我不确定它是否会通知观察者有关变化的信息.但如果确实如此,您的数据库将始终保持同步.但不要仅仅依赖于此,因为服务可能由于各种原因随时终止.

对于实际同步,请确保表中的“_ID”列是PRIMARY KEY.查询按“_ID”排序的内容提供程序.查询按“_ID”排序的自己的表并读取所有ID.现在遍历两个排序列表,插入您缺少的项目并删除缺少内容提供程序的项目.您还想删除使用其他SMS应用程序删除的邮件,不是吗? “插入或忽略”语句不会为您删除丢失的行.

总结

以上是内存溢出为你收集整理的更快/最快的方式来启动应用程序时获取新的短信 – Android全部内容,希望文章能够帮你解决更快/最快的方式来启动应用程序时获取新的短信 – Android所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1127337.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存