我的電池公司合作安裝,我們的手機都是基於Android(SDK 1.5),我們必須登錄我們的手機我們的應用程序,並給它的固件權限,如能力:錯誤具有管理員權限
安裝一個外部。在使用PackageManager應用程序(SDK 1.5)
這是我做過什麼:
File src = context.getFileStreamPath(fileName);
Uri mPackageURI = Uri.parse(src.getAbsolutePath());
PackageManager pm = context.getPackageManager();
int installFlags = 0;
try {
PackageInfo pi = pm.getPackageInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
if (pi != null) {
Log.debug(TAG, TAG + ":replacing " + fileName);
installFlags |= PackageManager.REPLACE_EXISTING_PACKAGE;
}
} catch (NameNotFoundException e) { }
try {
PackageInstallObserver observer = new PackageInstallObserver();
pm.installPackage(mPackageURI, observer, installFlags);
} catch (SecurityException e) {
//if the app is not signed by the manufacture it will get here a security exception
}
class PackageInstallObserver extends IPackageInstallObserver.Stub {
public void packageInstalled(String packageName, int returnCode) {
}
}
現在,這是奇怪的事情,我得到:
硅我們是manfucatures,我們沒有得到任何異常,而執行 pm.installPackage(mPackageURI,observer,installFlags);
,因爲我們已經有管理員權限簽訂了我們的應用程序。
但我們得到的是這個瘋狂的結果和手機正在重新啓動。
threadid=21: thread exiting with uncaught exception (group=0x4000fe70)
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): Uncaught handler: thread PackageManager exiting due to uncaught exception
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): *** EXCEPTION IN SYSTEM PROCESS. System will crash.
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): java.lang.NullPointerException
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): at
com.android.server.PackageManagerService.installPackageLI(PackageManagerService.java:3634)
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): at com.android.server.PackageManagerService.access$1500(PackageManagerService.java:120)
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): at com.android.server.PackageManagerService$5.run(PackageManagerService.java:3253)
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): at android.os.Handler.handleCallback(Handler.java:587)
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): at android.os.Looper.loop(Looper.java:123)
07-11 16:29:38.493: ERROR/AndroidRuntime(2561): at android.os.HandlerThread.run(HandlerThread.java:60)
方式二: 香港專業教育學院也嘗試過這種方式,我得到了不同勢異常:
*非常類似於第一種方式,只是主要的區別是在這一行:
String src = String.format("file:///data/data/com.mirs.agentcore/files/%s", fileName);
Uri mPackageURI = Uri.parse(src);
PackageManager pm = context.getPackageManager();
String src = String.format("file:///data/data/com.mirs.agentcore/files/%s", fileName);
Uri mPackageURI = Uri.parse(src);
PackageManager pm = context.getPackageManager();
int installFlags = 0;
.... //the rest of the code is the same as the First way(mention above)
這段代碼被執行後(第二種方式),電話繼續正常,但我得到這個異常:
十二月9日至12日:10:16.484:ERROR/PackageManager(6601):無法包文件複製到臨時文件。
我要做的第一件事就是查看PackageManagerService.java:3634處的代碼行。我試着在Google Code上尋找它,但這是HEAD版本,而不是v1.5版本:http://www.google.com/codesearch/p?hl=zh-CN#uX1GffpyOZk/services/java/com/android/ server/PackageManagerService.java&q = PackageManagerService.java&sa = N&cd = 1&ct = rc – MatrixFrog 2010-09-12 23:15:37
您是否曾經解決過這個問題? – Rob 2011-10-10 01:19:27