簡體   English   中英

嘿,我才剛開始在android中進行編碼並收到錯誤Permission Denial:不允許在android中發送廣播

[英]Hey , I am just started to code in android and getting error Permission Denial: not allowed to send broadcast in android

permission denial

我的活動代碼是

boolean isEnable= Settings.System.getInt(getContentResolver(),Settings.System.AIRPLANE_MODE_ON,0)==1;
Settings.System.putInt(getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnable?0:1);
intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state",!isEnable);
sendBroadcast(intent);

那是因為普通的SDK應用程序無法發送ACTION_AIRPLANE_MODE_CHANGED廣播。 如果您查看有關該Intent操作的文檔 ,則會看到:

這是受保護的意圖,只能由系統發送。

另請注意,您的AIRPLANE_MODE_ON內容可能不適用於API級別17(Android 4.2)或更高版本的設備

並且,請注意,普通的SDK應用程序無法擁有WRITE_SETTINGS權限。 如果您要構建自己的自定義Android ROM,則可以使用在該ROM中擁有該權限的應用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM