getLaunchIntentForPackage is null for some apps

后端 未结 3 1655
无人及你
无人及你 2020-12-01 14:08

I\'m building a service that sends a list of installed apps from an Android TV or a Fire TV to a mobile phone. The phone then sends back the package name of the app it wants

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 14:57

        Intent launchIntent = null;
    
                    try{
                            launchIntent = context.getPackageManager().getLeanbackLaunchIntentForPackage(pkgName);
                        } catch (java.lang.NoSuchMethodError e){
                        }
    
                        if (launchIntent == null) launchIntent = context.getPackageManager().getLaunchIntentForPackage(pkgName);
    
                    if (launchIntent != null)  {
                        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(launchIntent);
                    } else {
                       // failure message
                    }
    

提交回复
热议问题