Android 5.0 (L) Service Intent must be explicit in Google analytics

后端 未结 11 1640
南旧
南旧 2020-11-29 02:01

My code worked in <5 but in Android 5.0 I\'m running into an issue that I don\'t quite understand.

10-23 10:18:18.945: E/AndroidRuntime(8987): java.lang.I         


        
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 02:29

    I used this and it works great

     public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
         //Retrieve all services that can match the given intent
         PackageManager pm = context.getPackageManager();
         List resolveInfo = pm.queryIntentServices(implicitIntent, 0);
    
         //Make sure only one match was found
           if (resolveInfo == null || resolveInfo.size() != 1) {
            return null;
           }
    
         //Get component info and create ComponentName
         ResolveInfo serviceInfo = resolveInfo.get(0);
         String packageName = serviceInfo.serviceInfo.packageName;
         String className = serviceInfo.serviceInfo.name;
         ComponentName component = new ComponentName(packageName, className);
    
         //Create a new intent. Use the old one for extras and such reuse
         Intent explicitIntent = new Intent(implicitIntent);
    
         //Set the component to be explicit
         explicitIntent.setComponent(component);
    
         return explicitIntent;
     }
    

提交回复
热议问题