Created
September 14, 2021 09:13
-
-
Save MohitSharma0101/b3c980f1cd74e24f84607fddd8b51145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Make sure to handle read SMS permission before calling this function | |
fun getSmsCountByNumber(senderNumber:String) : Int{ | |
var totalSMS = 0 | |
val countryCode = "+91" | |
applicationContext.contentResolver.query( | |
Telephony.Sms.CONTENT_URI, | |
null, | |
null, | |
null, | |
null)?.use { cursor -> | |
while (cursor.moveToNext()) { | |
val number = cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS)); | |
if (number == senderNumber || number == countryCode + senderNumber ) { | |
totalSMS += 1 | |
} | |
} | |
Log.d("totalSMSCount",totalSMS.toString()) | |
} | |
return totalSMS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment