Java.lang.IllegalArgumentException:Service Intent must be explicit solution

Source: Internet
Author: User

Java.lang.IllegalArgumentException:Service Intent must be explicit

This means that the service must be explicitly called

This is how I used to bind the service.

He gave an error.

Because Google upgraded the SDK after 5.0

He requires that all service services must be explicitly called and not implicitly invoked

Workaround Use the following code

    /*** * Android L (Lollipop, API) introduced a new problem when trying to invoke implicit intent, * "Java.lang. Illegalargumentexception:service Intent must is explicit "* * If you are using a implicit Intent, and know only     1 target would answer this intent, * This method would help you turn the implicit intent into the explicit form. * * Inspired from So answer:http://stackoverflow.com/a/26318757/1446466     * @paramContext *@paramimplicitintent-the Original Implicit intent *@returnExplicit Intent created from the implicit original Intent*/     Public StaticIntent createexplicitfromimplicitintent (context context, Intent implicitintent) {//Retrieve all services that can match the given intentPackagemanager pm =Context.getpackagemanager (); List<ResolveInfo> ResolveInfo = pm.queryintentservices (implicitintent, 0); //Make sure-one match was found        if(ResolveInfo = =NULL|| Resolveinfo.size ()! = 1) {            return NULL; }        //Get Component Info and create ComponentNameResolveInfo serviceinfo = resolveinfo.get (0); String PackageName=ServiceInfo.serviceInfo.packageName; String ClassName=ServiceInfo.serviceInfo.name; ComponentName Component=Newcomponentname (PackageName, className); //Create a new intent. use the old one for extras and such reuseIntent explicitintent =NewIntent (implicitintent); //Set the component to be explicitexplicitintent.setcomponent (component); returnexplicitintent; }

Add a new code conversion function so that you can solve the problem

       New Intent ();        Intent.setaction ("Actionname.aidl.bank.BankService");        Intent intent1  new  Intent (createexplicitfromimplicitintent (context,intent));        Bindservice (intent1,conn,bind_auto_create);

Java.lang.IllegalArgumentException:Service Intent must be explicit solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.