이 코드를 사용하여 응용 프로그램에서 인터넷 3G 데이터를 활성화 또는 비활성화 할 수 있습니다. 숨겨진 리플렉션 기능과 그 모든 것에 대해 몇 가지 질문을 읽었지 만, 안드로이드가 매우 다른 수천 개의 휴대 전화에서 잘 작동하고있었습니다 (내 응용 프로그램은 PlayStore에 있으며 문제가 없었습니다). 그러나 나는 전화를 할 수없는 사람을 발견했기 때문에 걱정된다.데이터 사용 설정/해제
Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
이 결과로 :
java.lang.NoSuchFieldException : mService
try
{ final ConnectivityManager conman = (ConnectivityManager) MyContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if(conman == null) return false;
Class conmanClass = Class.forName(conman.getClass().getName());
if(conmanClass == null) return false;
Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
if(iConnectivityManagerField == null) return false;
iConnectivityManagerField.setAccessible(true);
Object iConnectivityManager = iConnectivityManagerField.get(conman);
if(iConnectivityManager == null) return false;
Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
if(iConnectivityManagerClass == null) return false;
Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
if(setMobileDataEnabledMethod == null) return false;
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(iConnectivityManager, true/false); //Here is where you choose to enable or to disable
return true; //Everything went OK
}catch(Exception e)
{ return false;
}
오류가 일치한다 : 내가 먼저 내가 사용하는 코드를 보여 드리죠
그 전화는 Jelly Bean을 사용하는 삼성 Galaxy SII입니다. 4.1.1 아이디어가 있으십니까? 나는 같은 문제를보고하기 시작하는 사람들을 두려워하고있다.
사용 권한 android : name = "android.permission.MODIFY_PHONE_STATE"/>이 사용 권한을 메인 프로그램의 – QuokMoon
에 추가했습니다. 이미 말했듯이, 그것은 이미 많은 휴대폰에서 작동하고 있습니다. 감사. – Ton