Android lock screen unread text message, missed phone

Source: Internet
Author: User

It is also the lock screen, there is no way to do the lock screen in the company are crazy.

The screen lock interface usually contains unread text messages and unanswered phone numbers, wrapped in a red circle, it is estimated that they are all imitated from Apple, but it does not matter, as a programmer, we will do our best to implement this function. Here we will not describe how to implement the interface, just briefly introduce the data acquisition method.

First, I understand where the text messages and missed calls are stored? Androd has a complete set of data access interfaces that provide third-party app access, but permissions must be declared before access. Permission Declaration is very simple, as long as you add the manifest file in the APK, which is not described here.

Because the lock screen is in the framework, you do not need to add the corresponding permissions. If a third-party app needs to implement similar functions, you must declare the permissions. This is why the user privacy of Android phones is easily leaked.

SMS storage location:/data/COM. Android. provider/telephony/databases/telphony. DB

Call record storage location:/data/COM. Android. provider/telephony/databases/mmssms. DB

How to obtain the number of unread SMS messages:

Because the short message contains short messages and MMS 2, you need to query the message twice. SMS is short message, and MMS is MMs.

Cursor curMms = null;int count = 0;try {String sql = Mms.READ + " = 0 and " + Mms.MESSAGE_TYPE + " != " + PduHeaders.MESSAGE_TYPE_DELIVERY_IND// + " and " + Mms.MESSAGE_TYPE + " != " + PduHeaders.MESSAGE_TYPE_READ_ORIG_IND;curMms = contentResolver.query(Uri.parse("content://mms/inbox"), null, sql, null, null);count = curMms.getCount();} catch (Exception e) {XLog.e(e.toString());e.printStackTrace();} finally {if (null != curMms) {curMms.close();}}Cursor curSms = null;try {curSms = contentResolver.query(Uri.parse("content://sms"), null, "type = 1 and read = 0", null, null);count += curSms.getCount();} catch (Exception e) {e.printStackTrace();XLog.e(e.toString());} finally {if (null != curSms) {curSms.close();}}

How to obtain the number of missed calls:

You need to query the call records for missed calls. There are three types of call records: power-off, incoming calls, and missed calls.

Uri uri = Calls.CONTENT_URI;String[] projects = new String[] { Calls._ID, Calls.NEW, Calls.DATE };String selections = Calls.NEW + " = ? AND " + Calls.TYPE + " = ? AND " + Calls.IS_READ + " = ? ";String[] args = { "1", Integer.toString(Calls.MISSED_TYPE), Integer.toString(0) };Cursor cursor = contentResolver.query(uri, projects, selections, args, null);int count = 0;if (cursor != null) {try {count = cursor.getCount();} finally {cursor.close();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.