当前位置:网站首页>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"/>
边栏推荐
- 2022年起重机司机(限桥式起重机)考试题库模拟考试平台操作
- Text editor for QT project practice - Episode 10
- 2022 simulated 100 questions of safety officer-c certificate examination and online simulated examination
- Single blind box removal, social blind box and friend blind box program source code
- QT electronic clock
- 断言(assert)的用法
- 51单片机多机通信
- A small crawler program written by beginners
- Uniapp encapsulated incentive advertisement, screen insert advertisement and banner advertisement
- 通过kubernetes可视化界面(rancher)安装kibana
猜你喜欢

Tiktok wallpaper applet, starlight wallpaper applet version 2.0, upgraded version

Text editor for QT project practice - Episode 10

丹麦技术大学首创将量子计算应用于能源系统潮流建模

The basic principle and application of iterator and enhanced for

ros(25):rqt_image_view报错Unable to load plugin for transport ‘compressed‘, error string

Using tcp/udp tools to debug the yeelight ribbon
最新QQ微信域名防红PHP程序源码+强制跳转打开

LLVM TargetPassConfig

Practical operation notes - notebook plus memory and ash cleaning

傳輸層 以字節為單比特的滑動窗口技術
随机推荐
[micro service sentinel] real time monitoring | RT | throughput | concurrency | QPS
Several ways for wechat applet to jump to the page are worth collecting
Scala classes inherit multiple attributes
The problem of multiple callback of video ads stimulated by applets (offcolse problem)
Helm chart warehouse operation
Syntax highlighting of rich text
Redis + Lua implementation of distributed interface current limiting
[redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly
Scala object blending trait
我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
51 single chip microcomputer multi computer communication
网上开户选哪个证券公司?网上开户安全么?
Custom control - round dot progress bar (imitating one key acceleration in security guard)
2022R1快开门式压力容器操作考题及答案
腾讯云国际云服务器网络访问丢包问题解决办法
Text editor for QT project practice - Episode 12
EVM Brief
Sanic service startup failed
QT(36)-rapidjson解析嵌套的json
新手看过来,带你一次性了解“软考”