Applications targeting Android O have a couple of new rules when using services, one of them is that we can't start services while the application is in background.
One of the requirements to be a default SMS application is: (from the Telephony.java javadoc)
* <li>In a service, include an intent filter for {@link
* android.telephony.TelephonyManager#ACTION_RESPOND_VIA_MESSAGE}
* (<code>"android.intent.action.RESPOND_VIA_MESSAGE"</code>) with schemas,
* <code>sms:</code>, <code>smsto:</code>, <code>mms:</code>, and <code>mmsto:</code>.
* This service must also require the {@link
* android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE} permission.
* <p>This allows users to respond to incoming phone calls with an immediate text message
* using your app.</p></li>
* </ul>
You can see my problem... because ACTION_RESPOND_VIA_MESSAGE needs a service with permission SEND_RESPOND_VIA_MESSAGE if we receive a phone call while the application is in background and the user rejects the call with a text message the service will fail to start.
1237-6018 W/Binder: Binder call failed.
java.lang.IllegalStateException: Not allowed to start service Intent { act=android.intent.action.RESPOND_VIA_MESSAGE dat=smsto:xxxxxxxxx cmp=APP_PACKAGE_NAME (has extras) }: app is in background uid null
Any idea how to fix this issue?