English 中文(简体)
地点管理者(真实)不返回供应商
原标题:LocationManager getProviders(true) not returning providers

因此,我基本上想开始聆听从<条码>广播接收器/代码”的单一更新,并出于某种原因,所有供应商都无法进入。 这里是法典。

LocationManager locationManager = (LocationManager)
                            context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setPowerRequirement(Criteria.POWER_LOW);
String majorProvider = locationManager.getBestProvider(criteria, true);
Log.d("location test", "major provider " + majorProvider);
List<String> allProviders = locationManager.getAllProviders();
for(int i=0; i < allProviders.size();i++) {
    Log.d("location test", "provider " + i + ": " + allProviders.get(i));
}
Log.d("location test", "enabled...");
allProviders = locationManager.getProviders(true);
for(int i=0; i < allProviders.size();i++) {
    Log.d("location test", "enabled provider " + i + ": " + allProviders.get(i));
}

和我的标识结果

04-09 11:23:35.763: D/location test(32576): major provider null
04-09 11:23:35.763: D/location test(32576): provider 0: network
04-09 11:23:35.763: D/location test(32576): provider 1: passive
04-09 11:23:35.763: D/location test(32576): provider 2: gps
04-09 11:23:35.763: D/location test(32576): enabled...

我猜测,问题在于,我从一个<条码>广播接收器<>/代码>上说了所有这一切,但我试图从其他地方转过来。 不可能从<条码>BroadcastReceiver进入地点管理?

最佳回答

那么,我就象这样说。 这完全是一个许可问题。 如果任何人再次这样做,就只增加使用许可以表明

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
问题回答

诚然,除了明显的许可声明外,你还可能需要人工向用户申请与地点有关的许可。 在批准后,请打电话getProviders,BestProvider

String[] perms = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION};    
ActivityCompat.requestPermissions(this, perms, REQ_LOCATION_PERMISSION);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签