单机器人GPS应用

单机器人GPS应用,gps,xamarin.android,Gps,Xamarin.android,在Monodroid中,我尝试访问GPS服务。我只需要一个定位对象 这一行显示一个错误: _locationManager.RequestLocationUpdate(locationManager.GpsProvider,1000,10,本) Java.Lang.SecurityException 堆栈跟踪在以下位置显示:0中的Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject,IntPtr jmethod,Android.Runtim

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

这一行显示一个错误:

  • _locationManager.RequestLocationUpdate(locationManager.GpsProvider,1000,10,本)
Java.Lang.SecurityException

堆栈跟踪在以下位置显示:0中的Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject,IntPtr jmethod,Android.Runtime.jValue[]参数)[0x00000]

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

我认为这与清单文件有关——我怀疑我丢失了一个属性,这样Monodroid就可以生成一个清单,告诉设备我正在使用GPS服务

我知道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的权限。要解决此项目上打开的上下文菜单问题,请选择属性->Android清单。如果没有任何内容,请单击链接“未找到AndroidMaifest.xml。单击以添加一个。”检查访问GPS数据的权限-访问位置。保存、重建、享受