0

I have implemented a implicit broadcast receiver to listen to phone calls

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
   <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>


    <receiver android:name=".CallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver> 

and I compiled and made the target 26 but still my broadcast receiver is working like usually.

As i read here https://developer.android.com/preview/features/background.html#broadcasts that this should not work anymore.

can anyone please tell to me if there is exception on my broadcast android.permission.READ_PHONE_STATE

user987760
  • 1,061
  • 3
  • 12
  • 26

2 Answers2

1

Are you sure you did set the compile SDK and the build tools to version 26?

compileSdkVersion 26
buildToolsVersion "26.0.0"

There is no implicit broadcast exception for the intent with the action android.intent.action.PHONE_STATE, since this intent is not directly targeted at your application and it is not listed as exception, so if even this works in a preview version of Android O, it might not work anymore in the production version of Android O.

An example of an intent that is excepted, is the intent with the action android.intent.action.MY_PACKAGE_REPLACED, since this intent is directed at one specific application, the application being updated.

The general idea is to save power (battery usage) by not unnecessarily waking up all applications with a generic broadcast.

You can work around this by registering a broadcast receiver in a service, which you likely want to be a foreground service, since there are also limitations on background services in Android O. Foreground services are enforced to show a notification (which can be minimal priority, so that the associated icon doesn't appear in the status bar, at least in Google's Android version). The idea here is that the user should be aware of anything that might use battery power.

M66B
  • 1,164
  • 1
  • 8
  • 16
  • Hey Sorry for my late reply, i was off-work, well yes i am targeting compileSdkVersion 26 buildToolsVersion "26.0.0" and I have a preview version of Android O Maybe you are right, this wont work in the Production Version but anyway i wish to have a solution for that – user987760 Jul 31 '17 at 08:06
0

Actually, "targeting" means not the compile version, but "target" version. So, check if you have next lines in your build.gradle:

defaultConfig {
    applicationId 'com.yourid'
    targetSdkVersion 26
}

For example, your app can compile on the newer one but target the previous:

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId 'com.yourid'
        minSdkVersion 21
        targetSdkVersion 25
}
Gaket
  • 6,533
  • 2
  • 37
  • 67