在执行下面的代码时,我没有得到android 4.2.1中的com.android.bluetooth
,但是当我在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);
}
}
答案 0 :(得分:-2)
您可能需要在代码中尝试 com.mediatek.bluetooth 作为包名称,而不是 com.android.bluetooth 。显然,新的Android版本使用此软件包。这对我有用。