您好我已经阅读了很多关于这个论点,但我认为如何更改android 5+中的首选网络有很多错误。
首先,我的应用可以使用 root ,但作为必要条件,必须留在Play商店。
为此,我认为有三种方法:
对于第二种方法存在一些大问题:
对于第三种方法,问题是沃达丰不是我的朋友:)
所以,让我们谈谈第一种方法:
内部游戏商店有很多应用程序可以根据权限更改首选网络,例如Auotomate:https://play.google.com/store/apps/details?id=com.llamalab.automate.ext.superuser&hl=it
我认为所有applciation都会在内部API中使用root会话中的反射调用此函数:https://github.com/android/platform_frameworks_base/blob/nougat-mr1-release/telephony/java/com/android/internal/telephony/ITelephony.aidl#L753
所以我试着用这段代码做这个...但冻结我的应用程序:
/**
* Function that change the preffered network
* @param Context context - The context of application
* @param String state_network - State that you want change ["2G" "3G" "4G" "2G/3G" "2G/3G/4G"]
* @return boolean
*/
public static String setDeviceNetwork(Context context, String state_network){
try {
Process process = null;
process = Runtime.getRuntime().exec("su");
process.waitFor();
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try{
Class<?> forName = Class.forName("com.android.internal.telephony.PhoneFactory");
try {
Method getDefaultPhone = forName.getMethod("getDefaultPhone", new Class[]{});
getDefaultPhone.setAccessible(true);
try {
Object mPhone = getDefaultPhone.invoke(null, new Object[]{}); //@TODO qui!
Method setPreferredNetworkType = mPhone.getClass().getMethod("setPreferredNetworkType", new Class[]{int.class, Message.class});
Method getPreferredNetworkType = mPhone.getClass().getMethod("getPreferredNetworkType", new Class[]{Message.class});
setPreferredNetworkType.setAccessible(true);
setPreferredNetworkType.invoke(mPhone, new Object[]{1, "1"});
return "WORK!";
}catch (IllegalAccessException e){
return "Error IllegalAccessException on run command change network";
}catch (InvocationTargetException e){
return "Error InvocationTargetException on run command change network";
}
}catch (NoSuchMethodException e){
return "Error NoSuchMethodException on find method";
}
}catch (ClassNotFoundException e){
return "Error ClassNotFoundException on find class";
}
} catch (IOException e) {
e.printStackTrace();
return "Error IOException on sudo command";
}
catch (InterruptedException e) {
e.printStackTrace();
return "Error InterruptException on sudo command";
}
}
有关此问题的任何解决方案?