Hello. I know that the SDK has classes and methods for accessing the call log in the Android OS. Is there the same opportunity for SMS? Those. the task is to get a list / array of incoming SMS with text, the number of the sender, date-time, and so on. information.

    3 answers 3

    Uri uriSms = Uri.parse("content://sms/inbox"); Cursor c = context.getContentResolver().query(uriSms, null,null,null,null); // column names for above provider: 0: _id 1: thread_id 2: address 3: person 4: date 5: protocol 6: read 7: status 8: type 9: reply_path_present 10: subject 11: body 12: service_center 13: locked 

    Other categories like sent can also be used instead of inbox.

    • Thank. It works. Are these all fields of the inbox table? Which field is responsible for the date / time of the message? The date field is just some huge number for each record from the database .. - zugzug
    • Not on the topic of the question, I’m just interested in - to get this kind of data, the application must have some specific access rights configured? - VioLet
    • Of course. In the manifest file you need to register the following <uses-permission android: name = "android.permission.READ_SMS" /> - zugzug
    • Everything. It seems he figured it out himself. A large value in the field is nothing other than the long type, time in milliseconds (possibly from the beginning of the Unix era — 1970, etc.). Using the getLong (4) method, we get our time in milliseconds and feed the input of the format () method of the DateFormat / SimpleDateFormat class with the required template. Thank you, alvin! - zugzug
    • clever! although it's not me, thanks, but to some dude from SOF.com - LackOfKnowledge
     mText.append("\n\n SMS сообщения"); mText.append("\n-------------------------------------------------------------"); Uri uriSms = Uri.parse("content://sms/"); Cursor cur = mainContext.getContentResolver().query(uriSms, null,null,null,null); startManagingCursor(cur); SimpleDateFormat format1 = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy"); if (cur.getCount() > 0){ while (cur.moveToNext()){ mText.append("\n" + format1.format(cur.getLong(4)) + " " + cur.getString(2) + ": " + cur.getString(12) ); mText.append("\n"); } } mText.append("\n########################################"); 

    I know that in the SDK there are classes and methods for accessing the call log in Android OS

    if you know you can help? where to read?

      AndroidManifest

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

      Layout

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft=" @dimen /activity_horizontal_margin" android:paddingRight=" @dimen /activity_horizontal_margin" android:paddingTop=" @dimen /activity_vertical_margin" android:paddingBottom=" @dimen /activity_vertical_margin" tools:context=".MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Get List Sms" android:id="@+id/button" android:layout_alignParentLeft="true" android:onClick="GetSMSList" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText" android:layout_below="@+id/button" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true"/> </RelativeLayout> 

      Method to receive a list of SMS

       public void GetSMSList(View v){ EditText mText = (EditText) findViewById(R.id.editText); mText.append("\n\n SMS сообщения"); mText.append("\n-------------------------------------------------------------"); Uri uriSms = Uri.parse("content://sms/"); Context context=this; Cursor cur = context.getContentResolver().query(uriSms, null,null,null,null); startManagingCursor(cur); SimpleDateFormat format1 = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy"); if (cur.getCount() > 0){ while (cur.moveToNext()){ mText.append("\n" + format1.format(cur.getLong(4)) + " " + cur.getString(2) + ": " + cur.getString(12) ); mText.append("\n"); } } mText.append("\n########################################"); }