RequestLocationUpdates抛出Java.Lang.Exception

时间:2014-11-23 11:54:49

标签: java android xamarin locationmanager

方法OnResume( _locationManager.RequestLocationUpdates )在三星上引发"类型异常' Java.Lang.Exception'" 注1(适用于SGS4)。

权限:android.permission.ACCESS_FINE_LOCATION和android.permission.ACCESS_COARSE_LOCATION已添加。

可以在github上找到来源:https://github.com/constructor-igor/sms2

[Activity (Label = "sms2", MainLauncher = true)]
public class MainActivity : Activity, ILocationListener
{
...
    private LocationManager _locationManager;
...
    protected override void OnCreate (Bundle bundle)
    {
       ...
      _locationManager = (LocationManager)GetSystemService(LocationService);
    }
    protected override void OnResume()
        {
            try
            {
                Log.Debug ("OnResume", "");
                base.OnResume ();

                m_smsSentBroadcastReceiver = new SMSSentReceiver();
                m_smsDeliveredBroadcastReceiver = new SMSDeliveredReceiver();

                RegisterReceiver(m_smsSentBroadcastReceiver, new IntentFilter("SMS_SENT"));
                RegisterReceiver(m_smsDeliveredBroadcastReceiver, new IntentFilter("SMS_DELIVERED"));

                _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
            }
            catch(Exception e) {
                Toast.MakeText(Application.Context, String.Format("OnResume failed, becasue '{0}'", e.Message), ToastLength.Long).Show();
            }
        }

添加完整堆栈的屏幕: http://cdn.vanillaforums.com/xamarin.vanillaforums.com/FileUpload/53/476688d11ac140e7c6aca6650348ce.png

1 个答案:

答案 0 :(得分:1)

您尝试使用的提供商不存在于该设备上。 您可以在documentation

中查看IllegalArgumentException的原因