Access to an access mailbox without UrI content (content //: sms)

I want to access the messages stored in the inbox through my android project. I tried the method of generating a URI for sms (content: // sms / inbox) and then request it for various parameters.

But I can not find the documentation for reading SMS messages Inbox standard Android Developr Docs. On various sites, it was mentioned that this content was removed from the standard sdk. The application may not support a higher version of android.

So, how can I create apllication for reading sms from the inbox, which is a reliable version of Android.

Please, help!!

+4
source share
2 answers

it works well in my milestone (sdk update 2.1)

public List<String> getSms() { Uri mSmsQueryUri = Uri.parse("content://sms/inbox"); List<String> messages = new ArrayList<String>(); Cursor cursor = null; try { cursor = mContentResolver.query(mSmsQueryUri, null, null, null, null); if (cursor == null) { Log.i(TAG, "cursor is null. uri: " + mSmsQueryUri); return messages; } for (boolean hasData = cursor.moveToFirst(); hasData; hasData = cursor.moveToNext()) { final String body = cursor.getString(cursor.getColumnIndexOrThrow("body")); messages.add(body); } } catch (Exception e) { Log.e(TAG, e.getMessage()); } finally { cursor.close(); } return messages; } 

Please make sure you have sms read permission:

 <uses-permission android:name="android.permission.READ_SMS"></uses-permission> 
+4
source

There is standard use of SmsMessage to send messages. http://developer.android.com/reference/android/telephony/SmsManager.html

However, I think the Content Provider solution is more stable than the Concrete Class, because the Content Provider is an abstract layer for accessing data in the case of multiple applications. In the long run, everything can be changed. For this, it will be beneficial for developers to use a design template, a wrapper class to manage the content provider (Facade), or use a data access template, etc.

In the Android configuration file, we can limit the sdk level to prevent something lost:

 <uses-sdk android:minSdkVersion="5" android:maxSdkVersion="8" android:targetSdkVersion="7" /> 

I am new to Android development, even if I read a lot of documents or books, I know that there is black magic in the source code. Changing the record too quickly to write the complete document (its relevance is not possible), so do not worry about changing AUTHORITY or Class.

my 2 cents

+1
source

Source: https://habr.com/ru/post/1312882/


All Articles