0

在执行以下代码时,我没有com.android.bluetooth在 android 4.2.1 中获得,但是当我在 4.1.2 中执行相同的代码时com.android.bluetooth,列表中会出现。是版本问题还是设备问题?

PackageManager pm = getPackageManager();
            List<ResolveInfo> appsList = pm.queryIntentActivities( in, 0);

            if(appsList.size() > 0){
                //select bluetooth
                String packageName = null;
                String className = null;
                boolean found = false;

                for(ResolveInfo info: appsList){
                    Toast.makeText(MainActivity.this, packageName, Toast.LENGTH_SHORT).show();
                  packageName = info.activityInfo.packageName;
                  if( packageName.equals("com.android.bluetooth")){
                     className = info.activityInfo.name;
                     found = true;
                     break;// found
                  }
                }
                if(! found){
                  Toast.makeText(this, "not found",
                                 Toast.LENGTH_SHORT).show();
                  // exit
                }
                else{
                    in.setClassName(packageName, className);
                    startActivity(in);
                }
            }
4

1 回答 1

-2

您可能想在代码中尝试com.mediatek.bluetooth作为包名,而不是com.android.bluetooth。显然,新的 Android 版本使用这个包。这对我有用。

于 2013-09-06T10:54:55.297 回答