-2

I've integrated some library from the third party into my android app.

They use background service with the location, but it caused java.lang.IllegalStateException error since Android 8 has updated the background location limits.

I've tried to add the following lines to avoid the error but it fails:

if(Build.VERSION.SDK_INT <= 25) { // below Android 8.0
         PushAd.startPush(activity);
}else{
         PushAd.disablePush(activity); 
}  


dependencies {
  implementation 'com.adlocus:library:3.5.7@aar'
}

Can I delete or remove the library, or stop the service in the main activity programmatically?


[Solved]

I discovered a possible solution to solve the problem, we can use PackageManager to enable/disable a Service/Receiver/Activity from third party library.

ComponentName component = new ComponentName(context, MyReceiver.class);
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED , PackageManager.DONT_KILL_APP);

Thanks Varun's answer.

Lambert
  • 1
  • 1
  • Should you be swapping the if-else clause contents? Or it's better to check with those supporting library to have more information. – CodeBulls Inc. Feb 05 '18 at 14:05

2 Answers2

1

Can I delete or remove the library... programmatically?

No.

Can I... stop the service in the main activity programmatically?

Possibly. Ask the developers of the library.

I've tried to add the following lines to avoid the error but it fails

Nobody knows what "it fails" means. Contact the developers of the library and ask them how to use it with Android 8.0+ devices.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

I discovered a possible solution to solve this problem, we can use PackageManager to enable/disable a Service/Receiver/Activity from third party library.

ComponentName component = new ComponentName(context, MyReceiver.class);
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED , PackageManager.DONT_KILL_APP);

Thanks Varun's answer.

Lambert
  • 1
  • 1