我想刷新android手機網絡android,但得到錯誤。我想讓它工作。如何打開/關閉蜂窩網絡Android?
我的代碼:
Settings.System.putInt(getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, mode ? 1 : 0);// Turning ON/OFF Airplane mode.
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);// creating intent and Specifying action for AIRPLANE mode.
intent.putExtra("state", !mode);// indicate the "state" of airplane mode is changed to ON/OFF
sendBroadcast(intent);// Broadcasting and Intent
我的清單文件有權限。
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
錯誤:
FATAL EXCEPTION: main
Process: com.zt.refreshnetwork, PID: 20221
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=20221, uid=10237
at android.os.Parcel.readException(Parcel.java:1684)
at android.os.Parcel.readException(Parcel.java:1637)
at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3537)
at android.app.ContextImpl.sendBroadcast(ContextImpl.java:881)
at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:421)
at com.zt.refreshnetwork.MainActivity.modifyAirplanemode(MainActivity.java:140)
at com.zt.refreshnetwork.MainActivity.airPlanemodeON(MainActivity.java:117)
at com.zt.refreshnetwork.MainActivity$1.onClick(MainActivity.java:46)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
'造成的:java.lang.SecurityException異常:無論用戶10237也不是當前進程android.permission.MODIFY_PHONE_STATE>'似乎是一個非常強烈的暗示。 – Michael
查看Logcat,您需要'MODIFY_PHONE_STATE'權限,但這僅適用於系統應用程序或根源設備([documentation](https://developer.android.com/reference/android/Manifest.permission.html #MODIFY_PHONE_STATE))。你究竟想要做什麼? –
@Michael不允許從pid = 20221,uid = 10237 –