6

At the moment I ask the user about app features to save battery power:

public void startSessionClick(View view) {

        String token = MyApp.getInstance().getPrefToken();
        if (!TextUtils.isEmpty(token)) {
            throw new RuntimeException("Token is not empty");
        }

        //todo hot-fix
        if (checkBatteryOptimization()) {
            Intent intent = new Intent(this, AuthEnterPhoneActivity.class);
            startActivityForResult(intent, REQUEST_CODE_ENTER_PHONE);
        } else {
            String packageName = getApplicationContext().getPackageName();
            Intent intent = new Intent();
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            getApplicationContext().startActivity(intent);
            //handleAnswer();
            startSessionClick(null);
        }
    }

How to track the agreement or refusal of dialogue?

At the moment when the agreement I just open the next activity (checking before that the stock settings) and if the user refuses, then again show this dialog.

Track I need for that would be in the event of failure to display a dialog with explanations.

abbath0767
  • 946
  • 2
  • 11
  • 31

1 Answers1

0

In your activity you can override a function onActivityResult. It will be called by the framework and passes a parameter resultCode

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == REQUEST_CODE_ENTER_PHONE) {
         if (resultCode == RESULT_OK) {
             // user accepted the permission request
             ...
         }
     }

See https://developer.android.com/reference/android/app/Activity#onActivityResult(int,%20int,%20android.content.Intent)

constanze
  • 76
  • 9