我目前面临与我的应用的部分用户的问题。出于某些原因,在某些手机上(主要是三星,在Android 6.0和7.0上),地理定位不起作用。 权限被授予,gps处于活动状态,但它根本无效。
有人对问题有所了解吗?它在大多数手机上运行良好,这就是我不能解决问题的原因。
感谢您的时间。
以下是处理地理定位的一些代码示例,即使我不认为问题来自此处。
int result2 = ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION);
int result3 = ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION);
return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED
&& result2 == PackageManager.PERMISSION_GRANTED && result3 == PackageManager.PERMISSION_GRANTED;
这个位于需要位置的片段上。它应该在此之前被授予,它更像是安全检查。
// Else, alert user and try again
else {
Log.d(TAG, "location is null");
prepareView(State.NoGeolocation);
// In case there's no Geolocation check if the user gave the proper permissions
// to the App. If not given, then a dialog will popup and ask the user for them.
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
return;
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getPotentialFriends();
}
}, 1000);
}