社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
测试手机:红米9A android10
开发环境:android studio 4.1.1
项目遇到的问题:原eclipse开发的app,不支持android 6.0及以上手机,安装不了。
最终结果:全部正常,升级到android studio,
找我200元改一个代码。
原因:应用的 targetSdkVersion 太旧 ( <17 )
建议:targetSdkVersion 30
https://blog.csdn.net/chenhao0568/article/details/50950227?spm=1001.2014.3001.5502
打开蓝牙和位置 ,如果没有提示打开,一定要手工打开,不然搜不到设备。
还不够
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
private static final int REQUEST_CODE_LOCATION_SETTINGS = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
if(!isLocationEnabled(this))
{
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, REQUEST_CODE_LOCATION_SETTINGS);
}
}
public static boolean isLocationEnabled(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return locationManager.isLocationEnabled();
}
boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (gps || network) {
return true;
}
return false;
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!