gpt4 book ai didi

gps - Monodroid GPS 使用

转载 作者:行者123 更新时间:2023-12-05 01:21:23 26 4
gpt4 key购买 nike

在 Monodroid 中,我正在尝试访问 GPS 服务。我只需要一个位置对象。

这一行报错:

  • _locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 1000, 10, 这个);

Java.Lang.SecurityException

堆栈跟踪显示在 Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject, IntPtr jmethod, Android.Runtime.jValue[] params) [0x00000] in :0

我有最新版本的 monodroid,我正在三星 Galaxy S II 物理设备上运行它。

我认为它与 Manifest 文件有关 - 我怀疑我缺少一个属性,以便 Monodroid 可以生成一个 list ,告诉设备我正在使用 GPS 服务。

我从http://docs.xamarin.com/android/advanced_topics/working_with_androidmanifest.xml知道Monodroid 使用 mandroid.exe 生成它自己的 AndroidManifest 文件。现在要么我必须自己修改 AndroidManifest.xml 文件,要么我必须让 mandroid 为我插入 GPS 东西。关键是:没有上面链接描述的“合并”文件——所以我只能通过 mandroid 来完成它。

那么我要创建并添加一个新文件供 mandroid 合并吗?

这是我正在做的:

...
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Locations;
...

namespace mynamespace
{
[Activity(Label = "My Activity")]
public class MainActivity : Activity, ILocationListener
{
...
#region Location Variables
LocationManager _locationManager;
#endregion

protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MainPage);

...
#region Location Setup
try
{
_locationManager = null;

if (/*user says to use location services*/)
{

_locationManager = (LocationManager)GetSystemService(Context.LocationService);
_locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 1000, 10, this);
}
}
catch (Exception ex)
{
_debug.Text = string.Format("{0} -- {1}",ex.Message,ex.StackTrace);
}

#endregion

...
}

#region Common Methods
...
#endregion

#region Events
...
#endregion

#region Location Services
public void OnLocationChanged(Location location)
{
_debug.Text = string.Format("long: {0}, lat: {1}", location.Longitude, location.Latitude);
}

public void OnProviderDisabled(string provider)
{
//throw new NotImplementedException();
}

public void OnProviderEnabled(string provider)
{
//throw new NotImplementedException();
}

public void OnStatusChanged(string provider, int status, Bundle extras)
{
//throw new NotImplementedException();
}
#endregion
}
}

最佳答案

您的应用没有权限访问 GPS。要解决项目上的这个打开的上下文菜单,请选择 Properties-> Android Manifest。如果什么都没有,请单击链接“未找到 AndroidMaifest.xml。单击以添加一个。”检查访问 GPS 数据的权限 - ACCESS_FINE_LOCATION。保存、重建、享受。

关于gps - Monodroid GPS 使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7416933/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com