2011-04-21 103 views
1

我試圖重新啓動(通過代碼)手機在某些時候。爲了做到這一點我做到這一點:重啓Android手機 - 許可拒絕


Intent i = new Intent(android.content.Intent.ACTION_REBOOT); 
    i.putExtra("nowait", 1); 
    i.putExtra("interval", 1); 
    i.putExtra("window", 0); 
    this.sendBroadcast(i); 

的問題是,即使我有在清單這一行:

uses-permission android:name="android.permission.REBOOT"(帶分隔符)。

當試圖執行它,它給了我一個錯誤:


Permission Denial: not allowed to send broadcast android.intent.action.REBOOT from pid= uid= gids= 

我讀了你應該創建一個.apk文件,並簽署SignApk,但我創建的關鍵/ openssl證書並用這些簽名,這也沒有運行,我繼續得到完全相同的錯誤。

你有關於如何解決這一點,並能夠重新啓動手機任何線索?我確實需要這樣做。

回答

0

http://www.krvarma.com/posts/android/security-permissions-in-android/

Permissions are granted to the application by package installer while installing. But not all the permissions will be granted to the system. There are some system permission which will not be granted to the user applications, but only to the system applications. Following are some of the permissions that may NOT be granted to the user application.

To get these permissions, the application must be signed with the key which used to sign the platform. This may be different for manufacturers. So it practically not possible to get these permissions granted to a user application.

3
public static final String ACTION_REBOOT 

Since: API Level 1 
Broadcast Action: Have the device reboot. **This is only for use by system code.** 
**This is a protected intent that can only be sent by the system.** 

Constant Value: "android.intent.action.REBOOT" 

http://developer.android.com/reference/android/content/Intent.html#ACTION_REBOOT

所以,除非你去關帶,並依靠其超級用戶,你將無法強制重新啓動。

1

對於通過代碼重新啓動Android設備u需要它僅到系統應用,或它們使用相同的密鑰作爲系統應用程序簽署的申請書授予「android.intent.action.REBOOT」權限。除此之外,還必須在Android Manifest android:sharedUserId =「android.uid.system」中添加一個標籤。以確保應用程序共享與系統應用程序相同的uid。

用於簽名系統應用的關鍵。對於設備製造商來說是獨一無二的,它不能被複制。