I'm making an app that accesses my call logs and sms logs and shows my monthly usage.
Is there any way to use READ_CALL_LOG, WRITE_CALL_LOG permission from other than setting it as default phone app?
I want to show sms history using READ_SMS permission, but should I set it as default text app like READ_CALL_LOG permission?
If so, please tell me how. I already set it as default phone, but I don't know how to set it as default sms app.
Like implementing InCallService to set the default calling app, what do I need to do to set it as the default sms app?
I added the necessary code to the manifest, and the Fragment requested to set it as the default sms app, but the default sms setting dialog popup does not appear.
<activity
android:name=".presentation.main.MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</activity>
<receiver
android:name=".receiver.SmsReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<service
android:name=".service.BaseSmsService"
android:exported="false"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</service>
<receiver
android:name=".receiver.MmsReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
Fragment.kt
private fun requestDefaultSmsApp() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val roleManager =
requireContext().getSystemService(AppCompatActivity.ROLE_SERVICE) as RoleManager
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
_requestDefaultSmsApp.launch(intent)
} else {
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT).apply {
putExtra(
Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
requireContext().packageName
)
}
startActivity(intent)
}
}
private val Context.isDefaultSmsApp: Boolean
get() = packageName == Telephony.Sms.getDefaultSmsPackage(this)
thank you!