2013-03-20 4 views
1

이 코드를 사용하여 응용 프로그램에서 인터넷 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 아이디어가 있으십니까? 나는 같은 문제를보고하기 시작하는 사람들을 두려워하고있다.

+0

사용 권한 android : name = "android.permission.MODIFY_PHONE_STATE"/>이 사용 권한을 메인 프로그램의 – QuokMoon

+0

에 추가했습니다. 이미 말했듯이, 그것은 이미 많은 휴대폰에서 작동하고 있습니다. 감사. – Ton

답변

1

분명히 Samsung (또는 ROM mod 작성자)이 해당 클래스를 다시 작성했으며 더 이상 데이터 멤버가 mService이 아닙니다. 이것은 그들의 권리 범위 내에 있습니다. 그들의 변화가 CTS에서 다룰 수있는 어떤 것도 깨뜨리지 않는 한, 그들은 프레임 워크 클래스의 내부 구현으로 원하는 것을 할 수 있습니다. 이것이 필자와 다른 안드로이드 전문가가 개발자에게 당신이 사용하는 것과 같은 스크립트 키디 트릭에 의존하지 말라고 말한 이유입니다.

"인터넷 3G 데이터 사용 또는 사용 중지"가 앱에 매우 중요하며 이것이 삼성 Galaxy SII의 재고 ROM에 영향을 미치는 것으로 판단되면 Play 스토어를 통해 해당 기기로의 전송을 차단해야합니다.

"인터넷 3G 데이터 사용 또는 사용 중지"가 앱에 중요하지 않은 경우 '미안,이 기능을 사용할 수 없음'또는 더 나은 예외 처리기를 추가하십시오.