我很难在运行 Android 6.0 的 XIAOMI REDMI NOTE 4 上询问 ACCESS_FINE_LOCATION。
我尝试使用地理编码器和位置。它适用于 iPhone 和 Android 8 上的三星(不知道名称)。
TL;DR:权限从不询问,并且在应用设置和小米中不可见。
这是我的代码:
安卓
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import java.util.Arrays;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL_GPS = "runtimepermission/access_fine_location";
private PermissionCallback getAccessFineLocationPermissionCallback;
private boolean rationaleJustShown = false;
private static final int GET_ACCESS_FINE_LOCATION_PERMISSION_REQUEST_ID = 1234;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL_GPS).setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, final MethodChannel.Result result) {
getAccessFineLocationPermissionCallback = new PermissionCallback() {
@Override
public void granted() {
rationaleJustShown = false;
result.success(0);
}
@Override
public void denied() {
rationaleJustShown = false;
result.success(1);
}
};
if (call.method.equals("hasPermission")) {
askPermission();
}
}
});
}
private void askPermission() {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
GET_ACCESS_FINE_LOCATION_PERMISSION_REQUEST_ID);
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
System.out.println("requestCode:" + requestCode);
for (int grantResult : grantResults) {
System.out.println("grandResult[i]:" + grantResult);
}
switch (requestCode) {
case GET_ACCESS_FINE_LOCATION_PERMISSION_REQUEST_ID:
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getAccessFineLocationPermissionCallback.granted();
} else {
getAccessFineLocationPermissionCallback.denied();
}
return;
}
}
public interface PermissionCallback {
void granted();
void denied();
}
扑:
static const _methodChannel = const MethodChannel('runtimepermission/access_fine_location');
Future<PermissionState> canGetLocation() async {
try {
final int result = await _methodChannel.invokeMethod('hasPermission');
return new Future.value(PermissionState.values.elementAt(result));
} on PlatformException catch (e) {
print('Exception ' + e.toString());
}
return new Future.value(PermissionState.DENIED);
}
它会抛出一个带有错误消息的 PlatformException:用户明确拒绝为此应用程序使用位置服务,或者当前在“设置”中禁用了位置服务。
在手机上,从不弹出弹窗,设置>已安装应用>我的应用>权限中不显示权限
你能帮助我吗 ?谢谢。