Java Code Examples for android.provider.Settings#ACTION_AIRPLANE_MODE_SETTINGS

The following examples show how to use android.provider.Settings#ACTION_AIRPLANE_MODE_SETTINGS . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void startCall(TLRPC.User user, final Activity activity, TLRPC.TL_userFull userFull){
	if(userFull!=null && userFull.phone_calls_private){
		new AlertDialog.Builder(activity)
				.setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed))
				.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("CallNotAvailable", R.string.CallNotAvailable,
						ContactsController.formatName(user.first_name, user.last_name))))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
				.show();
		return;
	}
	if (ConnectionsManager.getInstance(UserConfig.selectedAccount).getConnectionState() != ConnectionsManager.ConnectionStateConnected) {
		boolean isAirplaneMode = Settings.System.getInt(activity.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
		AlertDialog.Builder bldr = new AlertDialog.Builder(activity)
				.setTitle(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplaneTitle", R.string.VoipOfflineAirplaneTitle) : LocaleController.getString("VoipOfflineTitle", R.string.VoipOfflineTitle))
				.setMessage(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplane", R.string.VoipOfflineAirplane) : LocaleController.getString("VoipOffline", R.string.VoipOffline))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
		if (isAirplaneMode) {
			final Intent settingsIntent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
			if (settingsIntent.resolveActivity(activity.getPackageManager()) != null) {
				bldr.setNeutralButton(LocaleController.getString("VoipOfflineOpenSettings", R.string.VoipOfflineOpenSettings), new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						activity.startActivity(settingsIntent);
					}
				});
			}
		}
		bldr.show();
		return;
	}
	if (Build.VERSION.SDK_INT >= 23 && activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
		activity.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 101);
	} else {
		initiateCall(user, activity);
	}
}
 
Example 2
public static void startCall(TLRPC.User user, final Activity activity, TLRPC.TL_userFull userFull){
	if(userFull!=null && userFull.phone_calls_private){
		new AlertDialog.Builder(activity)
				.setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed))
				.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("CallNotAvailable", R.string.CallNotAvailable,
						ContactsController.formatName(user.first_name, user.last_name))))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
				.show();
		return;
	}
	if (ConnectionsManager.getInstance(UserConfig.selectedAccount).getConnectionState() != ConnectionsManager.ConnectionStateConnected) {
		boolean isAirplaneMode = Settings.System.getInt(activity.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
		AlertDialog.Builder bldr = new AlertDialog.Builder(activity)
				.setTitle(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplaneTitle", R.string.VoipOfflineAirplaneTitle) : LocaleController.getString("VoipOfflineTitle", R.string.VoipOfflineTitle))
				.setMessage(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplane", R.string.VoipOfflineAirplane) : LocaleController.getString("VoipOffline", R.string.VoipOffline))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
		if (isAirplaneMode) {
			final Intent settingsIntent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
			if (settingsIntent.resolveActivity(activity.getPackageManager()) != null) {
				bldr.setNeutralButton(LocaleController.getString("VoipOfflineOpenSettings", R.string.VoipOfflineOpenSettings), new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						activity.startActivity(settingsIntent);
					}
				});
			}
		}
		bldr.show();
		return;
	}
	if (Build.VERSION.SDK_INT >= 23 && activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
		activity.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 101);
	} else {
		initiateCall(user, activity);
	}
}
 
Example 3
@TargetApi(Build.VERSION_CODES.M)
private void startAirplaneModeSystemActivity() {
    try {
        Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
        startActivityForResult(intent, AIRPLANE_MODE_ACTIVITY_RESULT);
    } catch (ActivityNotFoundException ex) {
        Timber.w(ex, "startAirplaneModeSystemActivity(): Could not open Settings to change airplane mode");
        MyApplication.handleSilentException(ex);
        showCannotOpenAndroidSettingsDialog();
    }
}
 
Example 4
public static void startCall(TLRPC.User user, final Activity activity, TLRPC.UserFull userFull) {
	if (userFull != null && userFull.phone_calls_private) {
		new AlertDialog.Builder(activity)
				.setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed))
				.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("CallNotAvailable", R.string.CallNotAvailable,
						ContactsController.formatName(user.first_name, user.last_name))))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
				.show();
		return;
	}
	if (ConnectionsManager.getInstance(UserConfig.selectedAccount).getConnectionState() != ConnectionsManager.ConnectionStateConnected) {
		boolean isAirplaneMode = Settings.System.getInt(activity.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
		AlertDialog.Builder bldr = new AlertDialog.Builder(activity)
				.setTitle(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplaneTitle", R.string.VoipOfflineAirplaneTitle) : LocaleController.getString("VoipOfflineTitle", R.string.VoipOfflineTitle))
				.setMessage(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplane", R.string.VoipOfflineAirplane) : LocaleController.getString("VoipOffline", R.string.VoipOffline))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
		if (isAirplaneMode) {
			final Intent settingsIntent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
			if (settingsIntent.resolveActivity(activity.getPackageManager()) != null) {
				bldr.setNeutralButton(LocaleController.getString("VoipOfflineOpenSettings", R.string.VoipOfflineOpenSettings), (dialog, which) -> activity.startActivity(settingsIntent));
			}
		}
		bldr.show();
		return;
	}
	if (Build.VERSION.SDK_INT >= 23 && activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
		activity.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 101);
	} else {
		initiateCall(user, activity);
	}
}
 
Example 5
public static void startCall(TLRPC.User user, final Activity activity, TLRPC.UserFull userFull) {
	if (userFull != null && userFull.phone_calls_private) {
		new AlertDialog.Builder(activity)
				.setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed))
				.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("CallNotAvailable", R.string.CallNotAvailable,
						ContactsController.formatName(user.first_name, user.last_name))))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
				.show();
		return;
	}
	if (ConnectionsManager.getInstance(UserConfig.selectedAccount).getConnectionState() != ConnectionsManager.ConnectionStateConnected) {
		boolean isAirplaneMode = Settings.System.getInt(activity.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
		AlertDialog.Builder bldr = new AlertDialog.Builder(activity)
				.setTitle(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplaneTitle", R.string.VoipOfflineAirplaneTitle) : LocaleController.getString("VoipOfflineTitle", R.string.VoipOfflineTitle))
				.setMessage(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplane", R.string.VoipOfflineAirplane) : LocaleController.getString("VoipOffline", R.string.VoipOffline))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
		if (isAirplaneMode) {
			final Intent settingsIntent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
			if (settingsIntent.resolveActivity(activity.getPackageManager()) != null) {
				bldr.setNeutralButton(LocaleController.getString("VoipOfflineOpenSettings", R.string.VoipOfflineOpenSettings), (dialog, which) -> activity.startActivity(settingsIntent));
			}
		}
		bldr.show();
		return;
	}
	if (Build.VERSION.SDK_INT >= 23 && activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
		activity.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 101);
	} else {
		initiateCall(user, activity);
	}
}
 
Example 6
public void testAirplaneModeToOn() {
  UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
  // Activityの起動を監視するリスナーをセット
  mMainLaunched = false;
  uiAutomation
      .setOnAccessibilityEventListener(new OnAccessibilityEventListener() {
        @Override
        public void onAccessibilityEvent(AccessibilityEvent event) {
          if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
            // ウィンドウのコンテンツが変わった
            if (TARGET_PKG.equals(event.getPackageName())) {
              // MainActivityが起動した
              mMainLaunched = true;
            }
          }
        }
      });

  // MainActivity起動
  Activity target = launchActivity(TARGET_PKG, MainActivity.class, null);
  try {
    // MainActivity起動待ち
    do {
      Thread.sleep(1000);
    } while (!mMainLaunched);

    // 機内モードをOnにする
    // Settingsの起動
    Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getInstrumentation().getContext().startActivity(intent);

    // Settingsの起動待ち
    AccessibilityNodeInfo root;
    while (true) {
      root = uiAutomation.getRootInActiveWindow();
      if (root != null && SETTINGS_PKG.equals(root.getPackageName())) {
        break;
      } else {
        Thread.sleep(1000);
      }
    }

    // ボタンを押す
    List<AccessibilityNodeInfo> list = root
        .findAccessibilityNodeInfosByViewId("android:id/list");
    AccessibilityNodeInfo listViewInfo = list.get(0);
    AccessibilityNodeInfo airplaneModeView = listViewInfo.getChild(0);
    List<AccessibilityNodeInfo> checkList = airplaneModeView
        .findAccessibilityNodeInfosByViewId("android:id/checkbox");
    AccessibilityNodeInfo airplaneModeCheck = checkList.get(0);
    if (!airplaneModeCheck.isChecked()) {
      airplaneModeView.performAction(AccessibilityNodeInfo.ACTION_CLICK);
    }

    // Backキーを押してSettingsの終了
    uiAutomation.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);

    // 機内モード反映待ち
    Thread.sleep(10000);

    // TextViewの文字列検証
    String expected = target
        .getString(org.techbooster.uiautomationsample.R.string.airplane_mode_off);
    TextView textView = (TextView) target
        .findViewById(org.techbooster.uiautomationsample.R.id.text_view);
    assertEquals(expected, textView.getText().toString());

  } catch (Exception e) {
    fail(e.getMessage());
    e.printStackTrace();
  } finally {
    if (target != null) {
      target.finish();
    }
  }
}