On Android6.0, the following code is used:
Intent Intent = new Intent () intent.setaction ("Xxx.server"); Bindservice (Intent, Mconn, context.bind_auto_create);
The exception that prompted the warning:
Implicit intents with StartService is not safe
Check the source code, the original 5.0 must be forced to use the display mode to start the service.
private void Validateserviceintent (Intent service) { if (service.getcomponent () = = NULL && Service.getpackage () = null) { if (Getapplicationinfo (). targetsdkversion >= Build.version_codes. LOLLIPOP) { illegalargumentexception ex = new IllegalArgumentException ( "Service Intent must be explicit:" + Serv ICE); Throw ex; } else { LOG.W (TAG, "implicit intents with StartService is not safe:" + Service + "" + debug.getcallers (2, 3));
}}}
Workaround:
When you set the action, you also need to set the PackageName to start or bind the service class.
We use the system's Getpackagename function here to get the package name.
Intent Intent = new Intent () intent.setaction ("Xxx.server"); Intent.setpackage (Context.getpackagename ()); Bindservice (Intent, Mconn, context.bind_auto_create);
Perfect Solution Series Android5.0 above implicit intents with StartService is not safe