Qui*_*don 2 gps xamarin.android
在Monodroid中,我正在尝试访问GPS服务.我只需要一个位置对象.
这条线引出了一个错误:
java.lang.SecurityException异常
堆栈跟踪在Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject,IntPtr jmethod,Android.Runtime.jValue [] params)[0x00000]中显示:0
我有最新版本的monodroid,我在三星Galaxy S II物理设备上运行它.
我认为它与Manifest文件有关 - 我怀疑有一个我缺少的属性,以便Monodroid可以生成一个清单,告诉设备我正在使用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
}
}
Run Code Online (Sandbox Code Playgroud)
您的应用无权访问GPS.要在项目上解决此打开的上下文菜单,请选择Properties-> Android Manifest.如果没有任何内容,请单击链接"未找到AndroidMaifest.xml.单击以添加一个. "检查访问GPS数据的权限 - ACCESS_FINE_LOCATION.保存,重建,享受.
| 归档时间: |
|
| 查看次数: |
1758 次 |
| 最近记录: |