Skip to content

Commit

Permalink
Fix a crash if failed opening settings activity
Browse files Browse the repository at this point in the history
  • Loading branch information
nkming2 committed Oct 15, 2017
1 parent bf1aecd commit fb6cc40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/kotlin/com/nkming/powermenu/PermissionUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.nkming.powermenu

import android.Manifest
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
Expand Down Expand Up @@ -45,13 +46,24 @@ object PermissionUtils
Log.w("$LOG_TAG.requestSystemAlertWindow", "Invoking method on M-")
return
}
Toast.makeText(context, R.string.overlay_permission_required,
Toast.LENGTH_LONG).show()
Log.d("$LOG_TAG.requestSystemAlertWindow",
"Requesting overlay permission")
val i = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
i.data = Uri.parse("package:${BuildConfig.APPLICATION_ID}")
context.startActivity(i)
try
{
val i = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
i.data = Uri.parse("package:${BuildConfig.APPLICATION_ID}")
context.startActivity(i)
Toast.makeText(context, R.string.overlay_permission_required,
Toast.LENGTH_LONG).show()
}
catch (e: ActivityNotFoundException)
{
Log.e("$LOG_TAG.requestSystemAlertWindow",
"Activity ACTION_MANAGE_OVERLAY_PERMISSION not found", e)
Toast.makeText(context,
R.string.overlay_permission_settings_open_failed,
Toast.LENGTH_LONG).show()
}

pref.hasRequestOverlayPermission = true
pref.apply()
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@
<string name="pref_native_screenshot_title">Native screenshot</string>
<string name="pref_native_screenshot_summary_on">Using native</string>
<string name="pref_native_screenshot_summary_off">Using legacy</string>
<string name="overlay_permission_settings_open_failed">Failed opening Android Settings, please grant us permission to draw over other apps manually</string>
</resources>
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="su_failed">Failed running su command, not rooted?</string>
<string name="screenshot_succeed_fallback">Screenshot captured</string>
<string name="overlay_permission_required">Please grant us permission to draw over other apps</string>
<string name="overlay_permission_settings_open_failed">Failed opening Android Settings, please grant us permission to draw over other apps manually</string>
<string name="write_storage_required">Please grant us permission in order to take screenshots</string>

<string name="restart_mode_normal">Reboot</string>
Expand Down

0 comments on commit fb6cc40

Please sign in to comment.