小编Ama*_*rma的帖子

呼叫需要可能被用户拒绝的权限

我正在尝试创建一个每五分钟发送一次用户位置更新的应用程序.我想我的代码工作得很好,但是我收到有关应用程序正在使用的权限的错误.我很确定我已在清单文件中添加了权限.有人能告诉我什么是错的吗?这是我的代码.

MainActivity.java

LocationManager locationManager ;
String provider;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting LocationManager object
    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    // Creating an empty criteria object
    Criteria criteria = new Criteria();

    // Getting the name of the provider that meets the criteria
    provider = locationManager.getBestProvider(criteria, false);

    if(provider!=null && !provider.equals("")){

        // Get the location from the given provider
        Location location = locationManager.getLastKnownLocation(provider);
        locationManager.requestLocationUpdates(provider,5*60*1000,0,this);

        if(location!=null)
            onLocationChanged(location);
        else
            Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();

    }else{
        Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show();
    } …
Run Code Online (Sandbox Code Playgroud)

android runtime-error locationmanager

20
推荐指数
3
解决办法
9万
查看次数

标签 统计

android ×1

locationmanager ×1

runtime-error ×1