react-native-navigation的迁移库

ReactDevPermission.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.reactnativenavigation.react;
  2. import android.annotation.TargetApi;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.os.Build;
  6. import android.provider.Settings;
  7. import android.util.Log;
  8. import android.widget.Toast;
  9. import com.facebook.react.common.ReactConstants;
  10. import com.reactnativenavigation.NavigationApplication;
  11. public class ReactDevPermission {
  12. public static boolean shouldAskPermission() {
  13. return NavigationApplication.instance.isDebug() &&
  14. Build.VERSION.SDK_INT >= 23 &&
  15. !Settings.canDrawOverlays(NavigationApplication.instance);
  16. }
  17. @TargetApi(23)
  18. public static void askPermission(Context context) {
  19. if (shouldAskPermission()) {
  20. Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
  21. context.startActivity(serviceIntent);
  22. String msg = "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
  23. Log.w(ReactConstants.TAG, "======================================\n\n");
  24. Log.w(ReactConstants.TAG, msg);
  25. Log.w(ReactConstants.TAG, "\n\n======================================");
  26. for (int i = 0; i < 5; i++) {
  27. Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
  28. }
  29. }
  30. }
  31. }