我使用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. Restlet与GAE上的JSON效果不佳
- 2. 不能在android 6.0上使用android.contacts.SORT_ORDER
- 3. Spark reduceBykey效果不佳
- 4. 在Android上使用osmdroid显示GeoTIFF
- 5. Android - osmdroid - ResourceProxy.string
- 6. osmdroid的Roadmanager android
- 7. OSMDroid osmdroid-android-it项目无法编译
- 8. Ajax CalendarExtender在Windows Server 2012 R2上的渲染效果不佳
- 9. 在Windows上使用msysgit 1.7.4的钢筋get-deps效果不佳
- 10. CSS3转换在div或图像上效果不佳
- 11. 为什么Augment Reality在纵向方向上效果不佳
- 12. 在画布上绘制的文字反锯齿效果不佳
- 13. 如何在Android上实现物理效果,透视效果
- 14. 等效于OpenStreeMaps(OSMDroid)的com.google.android.maps.ItemizedOverlay.populate()
- 15. 在Android 3.0+上的ImageButton效果
- 16. onPostExecute在Android 4.2.2上得到空效果
- 17. 如何在Android上使用Flipboard效果
- 18. Android Studio中的OSMDroid
- 19. 图像字幕效果不佳
- 20. jQuery方法slideToggle()和resize()效果不佳
- 21. 在AOSP Android 6.0上更新WebView
- 22. WMF对PlayEnhMetafile渲染效果不佳
- 23. 确认对话框效果不佳
- 24. Canvas save()和restore()效果不佳
- 25. Bootstrap自定义图标效果不佳
- 26. 悬停效果不上IE9
- 27. 在找不到osmdroid 5.2
- 28. 叠加在osmdroid-Android的3.0.3.jar
- 29. ORMLite在Android上表现不佳?
- 30. OSMDroid映射上的LongPress不起作用
我们为你感到非常遗憾。但为什么要在这个网站上说这个?你应该直接向osmdroid报告这些事情。 – greenapps
我敢打赌,它是一个权限的东西 – spy