public static Intent implicit2ExplicitIntent(Context context,Intent implicitIntent){
  PackageManager pm=context.getPackageManager();
  List<ResolveInfo> resolveInfo=pm.queryIntentServices(implicitIntent,0);
  if (resolveInfo == null || resolveInfo.size() != 1) {
    return null;
  }
  ResolveInfo serviceInfo=resolveInfo.get(0);
  String packageName=serviceInfo.serviceInfo.packageName;
  String className=serviceInfo.serviceInfo.name;
  ComponentName component=new ComponentName(packageName,className);
  Intent explicitIntent=new Intent(implicitIntent);
  explicitIntent.setComponent(component);
  return explicitIntent;
}

public static Intent implicit2ExplicitIntent ( Context context , Intent implicitIntent ) { PackageManager pm = context . getPackageManager ( ) ; List < ResolveInfo > resolveInfo = pm . queryIntentServices ( implicitIntent , 0 ) ; if ( resolveInfo == null || resolveInfo . size ( ) != 1 ) { return null ; } ResolveInfo serviceInfo = resolveInfo . get ( 0 ) ; String packageName = serviceInfo . serviceInfo . packageName ; String className = serviceInfo . serviceInfo . name ; ComponentName component = new ComponentName ( packageName , className ) ; Intent explicitIntent = new Intent ( implicitIntent ) ; explicitIntent . setComponent ( component ) ; return explicitIntent ; }
android l ( lollipop , api 21 ) introduced a new problem when trying to invoke implicit intent , " java . lang . illegalargumentexception : service intent must be explicit " < p / > if you are using an implicit intent , and know only 1 target would answer this intent , this method will help you turn the implicit intent into the explicit form . < p / > inspired from so answer : http : / / stackoverflow . com / a / 26318757 / 1446466
