当前位置:网站首页>Contentresolver, get the SMS content
Contentresolver, get the SMS content
2022-06-25 01:05:00 【I am at odds with C】
xml、
<?xml version="1.0" encoding="utf-8" ?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <Button android:layout_width="match_parent" android:layout_height="100dp" android:text=" Get SMS permission " android:onClick="getperssion"/> </LinearLayout>
java
package com.commerce.myapplication; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import android.Manifest; import android.content.ContentResolver; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.PatternMatcher; import android.os.PowerManager; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void getperssion(View view) { ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_SMS},1); } private 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 (cursor!=null && cursor.getCount()>0){ while (cursor.moveToNext()){ int _id=cursor.getInt(0); String address= cursor.getString(1); String body= cursor.getString(2); Toast.makeText(MainActivity.this,body, Toast.LENGTH_SHORT).show(); } } } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if(requestCode==1){ for (int i=0;i<permissions.length;i++){ if (grantResults[i]== PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, " Permissions obtained successfully ", Toast.LENGTH_SHORT).show(); getSms(); }else { Toast.makeText(this, ""+" jurisdiction "+permissions[i]+" Application failed , Unable to read system SMS ", Toast.LENGTH_SHORT).show(); } } } } }
Green an
<uses-permission android:name="android.permission.READ_SMS"/>
边栏推荐
- Default methods for Scala sample classes
- 生成订单30分钟未支付,则自动取消,该怎么实现?
- 2021-04-18
- How to quickly open traffic master for wechat applet
- Simulation questions and answers of the latest national fire facility operator (senior fire facility operator) in 2022
- Use of file class filenamefilter & filefilter in io
- 移动安全工具-jar
- 丹麥技術大學首創將量子計算應用於能源系統潮流建模
- A small crawler program written by beginners
- Syntax highlighting of rich text
猜你喜欢

Scala IO reads by lexical units and numbers

Simulation questions and answers of the latest national fire facility operator (senior fire facility operator) in 2022

ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’

Using tcp/udp tools to debug the yeelight ribbon

图书馆管理系统代码源码(php+css+js+mysql) 完整的代码源码

Applet opening traffic master

【微服务|Sentinel】簇点链路|微服务集群环境搭建

【Redis实现秒杀业务④】一人一单,不可重复购买

Add information on the left and add parts on the right of the status bar

【Redis实现秒杀业务②】超卖问题的解决方案
随机推荐
2022 simulated 100 questions of safety officer-c certificate examination and online simulated examination
2022安全员-C证考试模拟100题及在线模拟考试
I brush the question I - copy the linked list with random pointer
最新QQ微信域名防红PHP程序源码+强制跳转打开
Scala classes inherit multiple attributes
Add information on the left and add parts on the right of the status bar
108 pages (40000 words) proposal for future apartment intelligent design platform project (version 2022)
【Redis实现秒杀业务④】一人一单,不可重复购买
Text border format and text block of rich text
51 single chip microcomputer multi computer communication
Scala trait exercise
Cobalt Strike安装教程
adb shell getevent
Infotnews | is the development of domestic NFT limited to digital collections?
EVM简略
A website for programmers with a monthly salary of 30K
2021-11-05
Golang示例续期锁:Redis+Channel+sync.Mutex
Kibana installation via kubernetes visual interface (rancher)
The interview questions and answers for the high-frequency software test of Dachang help you prepare for the golden nine silver ten