Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. private final static int REQUEST_CODE = 101;
  2.  
  3.  
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_overlay);
  8.  
  9. ButterKnife.bind(this);
  10.  
  11.  
  12. checkDrawOverlayPermission();
  13. }
  14.  
  15. private void checkDrawOverlayPermission() {
  16.  
  17. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  18. if (!Settings.canDrawOverlays(this)) {
  19.  
  20. Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + this.getPackageName()));
  21.  
  22. startActivityForResult(intent, REQUEST_CODE);
  23. finish();
  24. }
  25. }
  26. }
  27.  
  28. @Override
  29. public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  30. super.onActivityResult(requestCode, resultCode, data);
  31.  
  32. if (resultCode == REQUEST_CODE) {
  33.  
  34. Toast.makeText(this, "Ok", Toast.LENGTH_SHORT).show();
  35.  
  36. Intent intent = new Intent(getApplicationContext(), MainActivity.class);
  37. startActivity(intent);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement