3

以下のようにコードで使用したアプリケーションから、Android デバイスでデータ パケットの使用を無効または有効にしたいと考えています。

try {
        Method dataConnSwitchmethod;
        Class telephonyManagerClass;
        Object ITelephonyStub;
        Class ITelephonyClass;

        TelephonyManager telephonyManager = (TelephonyManager) NetworkMonitorDemoAppActivity.this.getSystemService(Context.TELEPHONY_SERVICE);

        if (telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED) {
            isEnabled = true;
        } else {
            isEnabled = false;
        }

        telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
        Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
        getITelephonyMethod.setAccessible(true);
        ITelephonyStub = getITelephonyMethod.invoke(telephonyManager);
        ITelephonyClass = Class
                .forName(ITelephonyStub.getClass().getName());

        if (isEnabled) {
            dataConnSwitchmethod = ITelephonyClass.getDeclaredMethod("disableDataConnectivity");
        } else {
            dataConnSwitchmethod = ITelephonyClass.getDeclaredMethod("enableDataConnectivity");
        }
        dataConnSwitchmethod.setAccessible(true);
        dataConnSwitchmethod.invoke(ITelephonyStub);
    } catch (Exception e) {
        System.out.println("error is occured in uses data packet enable & disable :-"+e.getMessage());
    }

しかし、このコードはうまく機能しません。私の友人がこの問題について私を助けてくれますか?

4

1 に答える 1

1

SO answer https://stackoverflow.com/a/4304110/582571でコードを参照していると思います

上記のリンクのコメントに「これは Gingerbread 2.3+ では機能しません」と記載されている別の SO 回答で詳細な説明を確認してください https://stackoverflow.com/a/5095956/582571

だから隠しAPIを使ったアプリは作らないほうがいい

于 2012-06-28T14:03:38.150 に答える