我使用Osmdroid 4.2創建了一個Android應用程序。一切工作正常,但在過去的兩週內,我看到與Android 6.0的Nexus設備上的問題:OSM地圖不加載,你只能看到地圖上的灰色背景。 Android 6.0上未顯示地圖。Osmdroid在Android 6.0上效果不佳
3
A
回答
4
osmdroid示例應用程序最近更新爲android m支持。基本上你必須要求用戶具有明確的網絡和存儲訪問權限。
這將引導您完成基本 http://developer.android.com/training/permissions/requesting.html
此相關的OSMdroid票 https://github.com/osmdroid/osmdroid/issues/178
這是相關的代碼複製並粘貼到你的啓動後續活動。注意,需要23個構建工具
import java.util.ArrayList;
import android.Manifest;
import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import org.osmdroid.MapActivity;
public class SampleLoader extends ListActivity {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
final int INTERNET=1;
final int NETSTATE=2;
final int LOCATION=3;
final int LOCATIONC=4;
final int WIFI=5;
final int STORAGE=6;
// ===========================================================
// Constructors
// ===========================================================
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.INTERNET);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.INTERNET)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need internet access to get map tiles if working with online sources", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.INTERNET},
INTERNET);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_NETWORK_STATE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_NETWORK_STATE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need to check network state", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_NETWORK_STATE},
NETSTATE);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need your location to place an icon on the map", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
LOCATION);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_COARSE_LOCATION)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Need your location to place an icon on the map", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
LOCATIONC);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_WIFI_STATE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_WIFI_STATE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "Access WIFI state", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_WIFI_STATE},
WIFI);
}
}
permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED){
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
Toast.makeText(this, "We store tiles to your devices storage to reduce data usage and for reading offline tile stores", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
STORAGE);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case INTERNET:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Online map sources will be unavailable", Toast.LENGTH_LONG).show();
}
return;
}
case NETSTATE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Online map sources will be unavailable", Toast.LENGTH_LONG).show();
}
return;
}
case LOCATION:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"My location will be unavailable via GPS", Toast.LENGTH_LONG).show();
}
return;
}
case LOCATIONC:
{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"My location will be unavailable via Network providers", Toast.LENGTH_LONG).show();
}
return;
}
case STORAGE:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Offline map data and caching will be unavailable", Toast.LENGTH_LONG).show();
}
return;
}
case WIFI:{
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this,"Data usage may not be optimized.", Toast.LENGTH_LONG).show();
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
}
+0
你爲什麼要檢查Internet和網絡狀態權限?它們都是「正常」權限,並且在應用程序安裝點默認授予它們。你可以在這裏查看正常的權限:http://developer.android.com/guide/topics/security/normal-permissions.html – Adrian
相關問題
- 1. GDI Antialiasing在Server 2008上效果不佳
- 2. Flot.js在android webview上執行效果不佳
- 3. Android均衡器預設效果不佳
- 4. pybrain效果不佳
- 5. Restlet與GAE上的JSON效果不佳
- 6. 不能在Android 6.0
- 7. Mkdirs Xamarin不能在Android 6.0上工作
- 8. 不能在android 6.0上使用android.contacts.SORT_ORDER
- 9. 切換類效果不佳
- 10. Spark reduceBykey效果不佳
- 11. R:大(?)visNetwork效果不佳
- 12. 在Android上使用osmdroid顯示GeoTIFF
- 13. caroufredsel在鉻中效果不佳
- 14. jquery功能在addClass後效果不佳
- 15. 其中Laravel在Carbon中效果不佳
- 16. Unity的TiltShift着色器在移動設備(Android)上的視覺效果不佳?
- 17. Android - osmdroid - ResourceProxy.string
- 18. osmdroid的Roadmanager android
- 19. CSS3轉換在div或圖像上效果不佳
- 20. Phonegap doens在視網膜顯示器上效果不佳
- 21. Ajax CalendarExtender在Windows Server 2012 R2上的渲染效果不佳
- 22. 在畫布上繪製的文字反鋸齒效果不佳
- 23. 爲什麼Augment Reality在縱向方向上效果不佳
- 24. 在Windows上使用msysgit 1.7.4的鋼筋get-deps效果不佳
- 25. OSMDroid osmdroid-android-it項目無法編譯
- 26. 如何在Android上實現物理效果,透視效果
- 27. 等效於OpenStreeMaps(OSMDroid)的com.google.android.maps.ItemizedOverlay.populate()
- 28. Android - 在畫布上發光效果
- 29. 如何在Android上使用Flipboard效果
- 30. 在Android上的降雪/降雨效果
我們爲你感到非常遺憾。但爲什麼要在這個網站上說這個?你應該直接向osmdroid報告這些事情。 – greenapps
我敢打賭,它是一個權限的東西 – spy