Unable to toggle airplane mode, espresso
I am trying to toggle airplane mode on kitkat version, on rooted emulator. I am using espresso for automation and i have scenario in which i have to switch on airplane mode and do some kind of steps in the app
I have modified time using the following method :
public static void amTime() {
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("date -s 20181015.070000");
outputStream.flush();
outputStream.writeBytes("exitn");
outputStream.flush();
su.wait(2000);
} catch (Exception e){
Log.e("Set Time", e.getMessage());
}
}
But I am unable to switch to airplane mode, i have tried different patterns... used the above method and modified following line with the adb commands
outputStream.writeBytes("mode airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 0");
can someone help with the code or adb script, by which i can switch on and off the airplane mode
android automation adb android-espresso
add a comment |
I am trying to toggle airplane mode on kitkat version, on rooted emulator. I am using espresso for automation and i have scenario in which i have to switch on airplane mode and do some kind of steps in the app
I have modified time using the following method :
public static void amTime() {
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("date -s 20181015.070000");
outputStream.flush();
outputStream.writeBytes("exitn");
outputStream.flush();
su.wait(2000);
} catch (Exception e){
Log.e("Set Time", e.getMessage());
}
}
But I am unable to switch to airplane mode, i have tried different patterns... used the above method and modified following line with the adb commands
outputStream.writeBytes("mode airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 0");
can someone help with the code or adb script, by which i can switch on and off the airplane mode
android automation adb android-espresso
The last two commands seems ok to me, but why you set the time usingdate...
and try to set airplane mode withadb shell settings...
? did you try to removeadb shell -c
from the string in the outputStream?
– TDG
Oct 19 '18 at 7:03
Yes tried with outputStream.writeBytes("settings put global airplane_mode_on 1"); ... still it is not changing to airplane mode..
– Tanaji Padwal
Oct 19 '18 at 8:06
I've tried it with a physical device - the device's icon hasn't changed, but the device itself entered airplane mode. Try it again and then try to toggle on mobile data. In my case I got a message that mobile data cannot be turned on while in airplane mode.
– TDG
Oct 20 '18 at 8:29
Its not working
– Tanaji Padwal
Oct 20 '18 at 13:13
add a comment |
I am trying to toggle airplane mode on kitkat version, on rooted emulator. I am using espresso for automation and i have scenario in which i have to switch on airplane mode and do some kind of steps in the app
I have modified time using the following method :
public static void amTime() {
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("date -s 20181015.070000");
outputStream.flush();
outputStream.writeBytes("exitn");
outputStream.flush();
su.wait(2000);
} catch (Exception e){
Log.e("Set Time", e.getMessage());
}
}
But I am unable to switch to airplane mode, i have tried different patterns... used the above method and modified following line with the adb commands
outputStream.writeBytes("mode airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 0");
can someone help with the code or adb script, by which i can switch on and off the airplane mode
android automation adb android-espresso
I am trying to toggle airplane mode on kitkat version, on rooted emulator. I am using espresso for automation and i have scenario in which i have to switch on airplane mode and do some kind of steps in the app
I have modified time using the following method :
public static void amTime() {
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("date -s 20181015.070000");
outputStream.flush();
outputStream.writeBytes("exitn");
outputStream.flush();
su.wait(2000);
} catch (Exception e){
Log.e("Set Time", e.getMessage());
}
}
But I am unable to switch to airplane mode, i have tried different patterns... used the above method and modified following line with the adb commands
outputStream.writeBytes("mode airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 1");
outputStream.writeBytes("adb shell -c settings put global airplane_mode_on 0");
can someone help with the code or adb script, by which i can switch on and off the airplane mode
android automation adb android-espresso
android automation adb android-espresso
edited Oct 18 '18 at 17:08
Fantômas
32.4k156388
32.4k156388
asked Oct 18 '18 at 16:01
Tanaji PadwalTanaji Padwal
114315
114315
The last two commands seems ok to me, but why you set the time usingdate...
and try to set airplane mode withadb shell settings...
? did you try to removeadb shell -c
from the string in the outputStream?
– TDG
Oct 19 '18 at 7:03
Yes tried with outputStream.writeBytes("settings put global airplane_mode_on 1"); ... still it is not changing to airplane mode..
– Tanaji Padwal
Oct 19 '18 at 8:06
I've tried it with a physical device - the device's icon hasn't changed, but the device itself entered airplane mode. Try it again and then try to toggle on mobile data. In my case I got a message that mobile data cannot be turned on while in airplane mode.
– TDG
Oct 20 '18 at 8:29
Its not working
– Tanaji Padwal
Oct 20 '18 at 13:13
add a comment |
The last two commands seems ok to me, but why you set the time usingdate...
and try to set airplane mode withadb shell settings...
? did you try to removeadb shell -c
from the string in the outputStream?
– TDG
Oct 19 '18 at 7:03
Yes tried with outputStream.writeBytes("settings put global airplane_mode_on 1"); ... still it is not changing to airplane mode..
– Tanaji Padwal
Oct 19 '18 at 8:06
I've tried it with a physical device - the device's icon hasn't changed, but the device itself entered airplane mode. Try it again and then try to toggle on mobile data. In my case I got a message that mobile data cannot be turned on while in airplane mode.
– TDG
Oct 20 '18 at 8:29
Its not working
– Tanaji Padwal
Oct 20 '18 at 13:13
The last two commands seems ok to me, but why you set the time using
date...
and try to set airplane mode with adb shell settings...
? did you try to remove adb shell -c
from the string in the outputStream?– TDG
Oct 19 '18 at 7:03
The last two commands seems ok to me, but why you set the time using
date...
and try to set airplane mode with adb shell settings...
? did you try to remove adb shell -c
from the string in the outputStream?– TDG
Oct 19 '18 at 7:03
Yes tried with outputStream.writeBytes("settings put global airplane_mode_on 1"); ... still it is not changing to airplane mode..
– Tanaji Padwal
Oct 19 '18 at 8:06
Yes tried with outputStream.writeBytes("settings put global airplane_mode_on 1"); ... still it is not changing to airplane mode..
– Tanaji Padwal
Oct 19 '18 at 8:06
I've tried it with a physical device - the device's icon hasn't changed, but the device itself entered airplane mode. Try it again and then try to toggle on mobile data. In my case I got a message that mobile data cannot be turned on while in airplane mode.
– TDG
Oct 20 '18 at 8:29
I've tried it with a physical device - the device's icon hasn't changed, but the device itself entered airplane mode. Try it again and then try to toggle on mobile data. In my case I got a message that mobile data cannot be turned on while in airplane mode.
– TDG
Oct 20 '18 at 8:29
Its not working
– Tanaji Padwal
Oct 20 '18 at 13:13
Its not working
– Tanaji Padwal
Oct 20 '18 at 13:13
add a comment |
1 Answer
1
active
oldest
votes
Simply create method as follows and call wherever required:
public static void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class conmanClass = Class.forName(conman.getClass().getName());
final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
connectivityManagerField.setAccessible(true);
final Object connectivityManager = connectivityManagerField.get(conman);
final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
}
Calling the method:
try {
CommonUtil.setMobileDataEnabled(mActivityTestRule.getActivity().getApplicationContext(),true);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Please note, this will set Data enabled = Off.. which is my requirement.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52878138%2funable-to-toggle-airplane-mode-espresso%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simply create method as follows and call wherever required:
public static void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class conmanClass = Class.forName(conman.getClass().getName());
final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
connectivityManagerField.setAccessible(true);
final Object connectivityManager = connectivityManagerField.get(conman);
final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
}
Calling the method:
try {
CommonUtil.setMobileDataEnabled(mActivityTestRule.getActivity().getApplicationContext(),true);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Please note, this will set Data enabled = Off.. which is my requirement.
add a comment |
Simply create method as follows and call wherever required:
public static void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class conmanClass = Class.forName(conman.getClass().getName());
final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
connectivityManagerField.setAccessible(true);
final Object connectivityManager = connectivityManagerField.get(conman);
final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
}
Calling the method:
try {
CommonUtil.setMobileDataEnabled(mActivityTestRule.getActivity().getApplicationContext(),true);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Please note, this will set Data enabled = Off.. which is my requirement.
add a comment |
Simply create method as follows and call wherever required:
public static void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class conmanClass = Class.forName(conman.getClass().getName());
final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
connectivityManagerField.setAccessible(true);
final Object connectivityManager = connectivityManagerField.get(conman);
final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
}
Calling the method:
try {
CommonUtil.setMobileDataEnabled(mActivityTestRule.getActivity().getApplicationContext(),true);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Please note, this will set Data enabled = Off.. which is my requirement.
Simply create method as follows and call wherever required:
public static void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class conmanClass = Class.forName(conman.getClass().getName());
final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
connectivityManagerField.setAccessible(true);
final Object connectivityManager = connectivityManagerField.get(conman);
final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
}
Calling the method:
try {
CommonUtil.setMobileDataEnabled(mActivityTestRule.getActivity().getApplicationContext(),true);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Please note, this will set Data enabled = Off.. which is my requirement.
answered Nov 21 '18 at 15:00
Tanaji PadwalTanaji Padwal
114315
114315
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52878138%2funable-to-toggle-airplane-mode-espresso%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The last two commands seems ok to me, but why you set the time using
date...
and try to set airplane mode withadb shell settings...
? did you try to removeadb shell -c
from the string in the outputStream?– TDG
Oct 19 '18 at 7:03
Yes tried with outputStream.writeBytes("settings put global airplane_mode_on 1"); ... still it is not changing to airplane mode..
– Tanaji Padwal
Oct 19 '18 at 8:06
I've tried it with a physical device - the device's icon hasn't changed, but the device itself entered airplane mode. Try it again and then try to toggle on mobile data. In my case I got a message that mobile data cannot be turned on while in airplane mode.
– TDG
Oct 20 '18 at 8:29
Its not working
– Tanaji Padwal
Oct 20 '18 at 13:13