Android DualSim, way / task / api to disable the second sim every day at the same hour

I use my phone for personal / work lines using dualsim (right now Xiaomi Mi5) with Android 7. I am looking for a way to use my work line (2nd sim) so that it will turn on at 6 am and be released at 22.00 from Monday to Friday .

After searching for some api applications in android, to do it myself, I could find a way to achieve it.

thanks

+5
source share
1 answer

Software solution

There is an application called Dual SIM Control , which can manage data and is compatible with Tasker, but it costs 1.20 euros. You can try the functionality in the free version . He claims to work without root, but I don’t know how it works.

Root solution

I did a little research and found the following to flip the data of one SIM card in a dual SIM phone with SDK version above 22:

Author: https://stackoverflow.com/users/463053/chuongpham

public static void setMobileNetworkfromLollipop(Context context) throws Exception { String transactionCode = getTransactionCode(context); String command = null; SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); // Loop through the subscription list ie SIM list. for (int i = 0; i < mSubscriptionManager.getActiveSubscriptionInfoCountMax(); i++) { if (transactionCode != null && transactionCode.length() > 0) { // Get the active subscription ID for a given SIM card. int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList().get(i).getSubscriptionId(); // Execute the command via `su` to turn off // mobile network for a subscription service. command = "service call phone " + transactionCode + " i32 " + subscriptionId + " i32 " + Settings.Global.getInt(context.getContentResolver(), "mobile_data", 0); executeCommandViaSu(context, "-c", command); } } } 

and

 private static void executeCommandViaSu(Context context, String option, String command) { boolean success = false; String su = "su"; for (int i=0; i < 3; i++) { // Default "su" command executed successfully, then quit. if (success) { break; } // Else, execute other "su" commands. if (i == 1) { su = "/system/xbin/su"; } else if (i == 2) { su = "/system/bin/su"; } try { // Execute command as "su". Runtime.getRuntime().exec(new String[]{su, option, command}); } catch (IOException e) { success = false; // Oops! Cannot execute `su` for some reason. // Log error here. } finally { success = true; } } } 
+2
source

Source: https://habr.com/ru/post/1266676/


All Articles