shounakmulay / Telephony

Flutter plugin for telephony features like query device sms directory, listen for incoming messages, retrieve various network parameters, etc.
https://telephony.shounakmulay.dev
MIT License
138 stars 126 forks source link

Permission denial SMS_RECEIVED trying to listen to incoming messages while app in background #130

Open zjjt opened 2 years ago

zjjt commented 2 years ago

Hi, as stated i am getting the following error when sms are coming in while my app is in background/paused. 01-19 12:29:37.998 32479 32620 I flutter : Unable to handle incoming background message. 01-19 12:29:37.998 32479 32620 I flutter : Instance of 'NotInitializedError'

After digging into logcat logs, i found it is because the app do not have the permission SMS_RECEIVED. 01-19 12:29:37.853 30143 30189 I Bugle : BroadcastReceiverAsyncWorkTracker: Acknowledging broadcast of com.google.android.apps.messaging.shared.receiver.ConfigSmsReceiver@14b110b 01-19 12:29:37.855 757 2334 W BroadcastQueue: Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x9000010 (has extras) } to com.transsion.scanningrecharger/.util.SmsBroadcastReceiver requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

When the app is in view(foreground ), everything works fine and i am able to listen to incoming sms and process them. I have tried running the app for now only with flutter run command both in debug and release mode on a real android device.

Please help me identify the issue.

Regards

zjjt commented 2 years ago

Please @shounakmulay help me out , i am working with flutter 2.8.1 ..Find an excerpt of the build.gradle ` android { compileSdkVersion 31

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.fastpaymobile"
    minSdkVersion 26
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}`

The RECEIVE_SMS permission is already set in my manifest file as well as the receiver...I also request the permissions using the instance in one of the initialization methods of my code, but still i keep getting this error message when a new sms is coming in ...I ve tried detecting when the app is is background and requests the permissions again via the backgroundInstance However it still fails. I do not know what else to do , does android 11 restricts this feature, even though i have the permissions(bool from await telephony.requestPhoneAndSmsPermissions;)?

Please help