Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the function of viewing system SMS with ContentProvider in Android

Shulou Source: shulou.com Published: 2022-06-02 15:29:21 10月05日 Update

This article mainly introduces "how Android uses ContentProvider to view system SMS function". In daily operation, I believe many people have doubts about how Android uses ContentProvider to view system SMS function. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the question of "how to view system SMS function with Android using ContentProvider". Next, please follow the editor to study!

Activity_main.xml

Sms.java

Public class Sms {private int id; private String address; private String body; public Sms (int id, String address, String body) {this.id = id; this.address = address; this.body = body;} public int getId () {return id;} public void setId (int id) {this.id = id;} public String getAddress () {return address } public void setAddress (String address) {this.address = address;} public String getBody () {return body;} public void setBody (String body) {this.body = body;}}

MainActivity.java

Public class MainActivity extends AppCompatActivity {private TextView tv_show; private Button bt_show; private List list=new ArrayList (); private String text= ""; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); tv_show=findViewById (R.id.tv_show); bt_show=findViewById (R.id.bt_show) } public void show (View view) {ActivityCompat.requestPermissions (MainActivity.this,new String [] {Manifest.permission.READ_SMS}, 1);} public void getSms () {Uri uri= Uri.parse ("content://sms/"); ContentResolver contentResolver=getContentResolver () Cursor cursor = contentResolver.query (uri, new String [] {"_ id", "address", "body"}, null, null, null); if (cursorsor.getCount () > 0) {if (listings empty null) {list.clear ();} text= "" While (cursor.moveToNext ()) {int id=cursor.getInt (0); String name=cursor.getString (1); String body=cursor.getString (2); Sms sms=new Sms (id,name,body); list.add (sms);} for

Tags: Text messages functions systems learning more help practical next content numbers mobile phones mobile numbers articles methods permissions theory knowledge articles websites materials Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Docker Apple vpn Huawei