Monodroidでは、私はGPSサービスにアクセスしようとしています。必要なのはロケーションオブジェクトだけです。Monodroid GPSの使用
この行はエラーthorws:
- _locationManager.RequestLocationUpdates(LocationManager.GpsProvider 1000、10、これを)。
Java.Lang.SecurityException
スタックトレースがAndroid.Runtime.JNIEnv.CallVoidMethodに言う(のIntPtr jオブジェクト、のIntPtr jmethod、Android.Runtime.jValue [] paramsは)[0x00000]:0
私はモノドイドロイドの最新バージョンを持っており、Samsung Galaxy S II物理デバイス上で実行しています。
私はそれがManifestファイルと関係があると思います.MododroidがGPSサービスを使用していることを示すマニフェストを生成できるように、私は行方不明です。
私はhttp://docs.xamarin.com/android/advanced_topics/working_with_androidmanifest.xmlから、Monodroidがmandroid.exeを使用してAndroidManifestファイルを生成していることを知っています。今度は、AndroidManifest.xmlファイルを自分で修正する必要があります。あるいは、私のためにGPSを挿入するために、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
}
}