Java 无法创建和更改n/acct/uid_10010:只读文件系统
我不确定,但是这个错误和我的应用程序没有返回一些安卓手机用户的位置之间是否有任何联系,在一些安卓手机中,它工作正常,但在联想k5和其他手机中,它没有工作,也没有返回位置Java 无法创建和更改n/acct/uid_10010:只读文件系统,java,android,android-studio,Java,Android,Android Studio,我不确定,但是这个错误和我的应用程序没有返回一些安卓手机用户的位置之间是否有任何联系,在一些安卓手机中,它工作正常,但在联想k5和其他手机中,它没有工作,也没有返回位置 import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.location.Criteria; import android.location.Location
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.widget.Toast;
import java.util.List;
public class LocationForAlive implements LocationListener {
private Context context;
private LocationManager locationManager;
private String mProvider;
private String GPS = "gps";
private String NETWORK = "network";
private String PASSIVE = "passive";
private double latitude;
private double longitude;
private double arr[] = new double[2];
private static final String TAG = "Location";
LocationForAlive(Context context) {
this.context = context;
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setCostAllowed(false);
mProvider = locationManager.getBestProvider(criteria, false);
List<String> providersList = locationManager.getAllProviders();
boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
boolean isPassiveEnabled = locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER);
if (isGPSEnabled || isNetworkEnabled || isPassiveEnabled) {
Location location = returnLocation(LocationManager.GPS_PROVIDER);
if(location == null){
location = returnLocation(LocationManager.NETWORK_PROVIDER);
if(location == null){
location = returnLocation(LocationManager.PASSIVE_PROVIDER);
if(location == null){
Log.d(TAG, "Error");
Toast.makeText(context, "Error!!!!", Toast.LENGTH_LONG).show();
}else{
onLocationChanged(location);
}
}else{
onLocationChanged(location);
}
}else{
onLocationChanged(location);
}
}
}
public double[] getLocation(){
arr[0] = latitude;
arr[1] = longitude;
return arr;
}
private Location returnLocation(String providerName){
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return null;
}
locationManager.requestLocationUpdates(providerName, 2000, 10, this);
Location location = locationManager.getLastKnownLocation(providerName);
if (location != null) {
return location;
}else{
return null;
}
}
@Override
public void onLocationChanged(Location location) {
if(location!=null){
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
}
导入android.Manifest;
导入android.content.Context;
导入android.content.pm.PackageManager;
导入android.location.Criteria;
导入android.location.location;
导入android.location.LocationListener;
导入android.location.LocationManager;
导入android.os.Bundle;
导入android.support.v4.app.ActivityCompat;
导入android.util.Log;
导入android.widget.Toast;
导入java.util.List;
公共类LocationForAlive实现LocationListener{
私人语境;
私人场所经理场所经理;
私有字符串提供程序;
专用字符串GPS=“GPS”;
专用字符串NETWORK=“NETWORK”;
私有字符串PASSIVE=“PASSIVE”;
私人双纬度;
私人双经度;
专用双arr[]=新双arr[2];
私有静态最终字符串TAG=“Location”;
LocationForAlive(上下文){
this.context=上下文;
locationManager=(locationManager)context.getSystemService(context.LOCATION\u服务);
标准=新标准();
条件。允许设置成本(false);
mProvider=locationManager.getBestProvider(条件,false);
List providersList=locationManager.getAllProviders();
布尔值isGPSEnabled=locationManager.isProviderEnabled(locationManager.GPS\U提供程序);
布尔值isNetworkEnabled=locationManager.isProviderEnabled(locationManager.NETWORK\u提供程序);
布尔值isPassiveEnabled=locationManager.isProviderEnabled(locationManager.PASSIVE_提供程序);
如果(isGPSEnabled | | | isNetworkEnabled | | isPassiveEnabled){
位置=返回位置(LocationManager.GPS\U提供程序);
if(位置==null){
位置=返回位置(LocationManager.NETWORK\u PROVIDER);
if(位置==null){
位置=返回位置(LocationManager.PASSIVE\u提供程序);
if(位置==null){
Log.d(标记“错误”);
Toast.makeText(上下文,“Error!!”,Toast.LENGTH_LONG.show();
}否则{
onLocationChanged(位置);
}
}否则{
onLocationChanged(位置);
}
}否则{
onLocationChanged(位置);
}
}
}
公共双[]getLocation(){
arr[0]=纬度;
arr[1]=经度;
返回arr;
}
私有位置returnLocation(字符串提供程序名称){
if(ActivityCompat.checkSelfPermission(context,Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予和&ActivityCompat.checkSelfPermission(context,Manifest.permission.ACCESS\u LOCATION)!=PackageManager.permission\u已授予){
考虑到呼叫
//ActivityCompat#请求权限
//在此处请求缺少的权限,然后覆盖
//public void onRequestPermissionsResult(int-requestCode,字符串[]权限,
//int[]格兰特结果)
//处理用户授予权限的情况。请参阅文档
//对于ActivityCompat,请请求权限以获取更多详细信息。
返回null;
}
locationManager.RequestLocationUpdate(providerName,2000,10,this);
Location Location=locationManager.getLastKnownLocation(providerName);
如果(位置!=null){
返回位置;
}否则{
返回null;
}
}
@凌驾
已更改位置上的公共无效(位置){
如果(位置!=null){
纬度=位置。getLatitude();
longitude=location.getLongitude();
}
}
@凌驾
状态已更改的公共void(字符串s、int i、Bundle){
}
@凌驾
已提供已启用的公共void(字符串s){
}
@凌驾
公共无效onProviderDisabled(字符串s){
}
}
在此发布您的代码欢迎访问stackoverflow.com。请花些时间阅读,特别是“和”部分。也请阅读。最后,请学习如何创建一个。