简体   繁体   English

onActivityResult()永远不会被调用

[英]onActivityResult() never gets called

I have a class used as interface inside my MainActivity.java : 我在MainActivity.java中有一个用作接口的类:

 public class prova{
    prova(){
    }
    @JavascriptInterface
    public void displayGPSRequest() {            
        result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
            @Override
            public void onResult(LocationSettingsResult result) {
                final Status status = result.getStatus();
                switch (status.getStatusCode()) {
                    case LocationSettingsStatusCodes.SUCCESS:
                        Log.i(TAG, "All location settings are satisfied.");
                        break;
                    case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                        Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to upgrade location settings ");

                        try {
                            // Show the dialog by calling startResolutionForResult(), and check the result
                            // in onActivityResult().
                            status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
                        } catch (IntentSender.SendIntentException e) {
                            Log.i(TAG, "PendingIntent unable to execute request.");
                        }
                        break;
                    case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                        Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog not created.");
                        break;
                }
            }

            public void onActivityResult(int requestCode, int resultCode, Intent data)
            {
             //final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
                switch (requestCode)
                {
                    case REQUEST_CHECK_SETTINGS:
                        switch (resultCode)
                        {
                            case Activity.RESULT_OK:
                            {
                                // All required changes were successfully made
                                Toast.makeText(MainActivity.this, "Location enabled by user!", Toast.LENGTH_LONG).show();
                                break;
                            }
                            case Activity.RESULT_CANCELED:
                            {
                                // The user was asked to change settings, but chose not to
                                Toast.makeText(MainActivity.this, "Location not enabled, user cancelled.", Toast.LENGTH_LONG).show();
                                break;
                            }
                            default:
                            {
                                break;
                            }
                        }
                        break;
                }
            }
        });
    }
}

Inside the function displayGPSRequest() I have startResolutionForResult() that should call the method onActivityResult() but it never does. 在函数displayGPSRequest()我具有startResolutionForResult() ,该函数应调用onActivityResult()方法,但从不执行。 I tried to see other posts where they used fragments but I don't have really understood them. 我尝试查看其他帖子中使用了片段的帖子,但我并没有真正理解它们。 I hope you can help with this. 希望您能提供帮助。

应该在关联的Activity中重写onActivityResult-当前,您只是在ResultCallback中声明一个永远不会被调用的方法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM