简体   繁体   English

接收广播意图时出错{act = android.location.PROVIDERS_CHANGED flg = 0x10}

[英]Error receiving broadcast Intent { act=android.location.PROVIDERS_CHANGED flg=0x10 }

I have broadcast like this: 我已经这样广播了:

private final BroadcastReceiver locationReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().matches(LocationManager.PROVIDERS_CHANGED_ACTION)){
            //do stuff
            startLocationUpdates();
        }
    }
};

When the user turns on the gps, locationReceiver should executre the statLocationUpdates(). 当用户打开gps时,locationReceiver应该执行statLocationUpdates()。 This is the code inside that method: 这是该方法中的代码:

protected void startLocationUpdates() {
    try
    {
        LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
        if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
        {
            buildAlertMessageNoGps();
        }
    }
    catch (SecurityException ex)
    {

    }

There is a problem with line LocationServices.FusedLocationApi... I cant figure out why. LineService.FusedLocationApi行有问题...我不知道为什么。 But this is what the log says: 但这就是日志所说的:

02-28 21:31:40.747 21273-21273/com.theapplabperu.hangover E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.theapplabperu.hangover, PID: 21273
                                                                        java.lang.RuntimeException: Error receiving broadcast Intent { act=android.location.PROVIDERS_CHANGED flg=0x10 } in com.theapplabperu.hangover.View.Activity.ActivitySplash$11@f6e8393
                                                                            at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:932)
                                                                            at android.os.Handler.handleCallback(Handler.java:815)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                            at android.os.Looper.loop(Looper.java:207)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5728)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
                                                                         Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet.

I read another post but I didn't get how to solve it yet. 我读了另一篇文章,但还没有解决方法。 Any idea? 任何想法?

UPDATE: 更新:

I actually create my googleapiclient in the onCreate method: 我实际上是在onCreate方法中创建了googleapiclient:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    myContext = this;
    myActivity = this;
    mVisible = true;


    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(myContext)
                .addConnectionCallbacks(ActivitySplash.this)
                .addOnConnectionFailedListener(ActivitySplash.this)
                .addApi(LocationServices.API)
                .build();
    }

It's on your exception: 这是您的例外:

Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet.

Please make sure that your mGoogleApiClient is connected before using it. 使用前请确保您的mGoogleApiClient已连接。 You may use mGoogleApiClient.isConnected() to verify and mGoogleApiClient.connect() to connect it. 您可以使用mGoogleApiClient.isConnected()进行验证,并使用mGoogleApiClient.connect()进行连接。

Edit: 编辑:

Another thing you can do is to make sure you register the broadcast after the mGoogleApiClient has been connected. 您可以做的另一件事是确保在连接mGoogleApiClient之后注册广播。 You may do so by placing it on the onConnected callback. 您可以将其放在onConnected回调中。

Try moving your googleApiClient creation to onCreate() . 尝试将googleApiClient创建的内容移动到onCreate() https://stackoverflow.com/a/29440779/4904995 https://stackoverflow.com/a/29440779/4904995

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JSONObject接收广播意图{act = location_update flg = 0x10(有其他功能)}时出错 - Error receiving broadcast Intent { act=location_update flg=0x10 (has extras) } with JSONObject GCM android错误接收广播意图{act = DISPLAY.MESSAGE flg = 0x10(有其他功能) - GCM android Error receiving broadcast Intent { act=DISPLAY.MESSAGE flg=0x10 (has extras) 接收广播Intent时出错{act = android.bluetooth.device.action.FOUND flg = 0x10} - Error receiving broadcast Intent { act=android.bluetooth.device.action.FOUND flg=0x10} GCM android错误接收广播意图{act = PATH.DISPLAY_MESSAGE flg = 0x10(有附加功能) - GCM android Error receiving broadcast Intent { act=PATH.DISPLAY_MESSAGE flg=0x10 (has extras) ANR意图播报{act = com.google.android.c2dm.intent.RECEIVE flg = 0x10 cmp = receiver.GcmBroadcastReceiver(有其他功能)} - ANR Broadcast of Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 cmp=receiver.GcmBroadcastReceiver (has extras) } 开启/关闭GPS是否会广播android.location.PROVIDERS_CHANGED消息? - Does turning on/off GPS broadcast the android.location.PROVIDERS_CHANGED message? ANR 意图广播 { act=android.intent.action.SCREEN_OFF flg=0x50000010 } - ANR Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50000010 } ANR 意图广播 { act=android.intent.action.SCREEN_ON flg=0x50200010(有额外内容)} - ANR Broadcast of Intent { act=android.intent.action.SCREEN_ON flg=0x50200010 (has extras) } 意图广播 { act=android.intent.action.SCREEN_ON flg=0x50200010 } - Broadcast of Intent { act=android.intent.action.SCREEN_ON flg=0x50200010 } 棉花糖应用程序权限:android.location.PROVIDERS_CHANGED未触发 - Marshmallow app-permission: android.location.PROVIDERS_CHANGED is not fired
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM