1

It's weird I found PackageManager has public APIs like installPackage(...)/deletePackage(...) although in the comment it's marked as Hide, here http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/content/pm/PackageManager.java#PackageManager.deletePackage%28java.lang.String%2Candroid.content.pm.IPackageDeleteObserver%2Cint%29, but the reference page google provides hide this API.

So my question is how can I access such APIs?

Thank you all very much for help.

Kindest regards, Nessus.

user1105115
  • 483
  • 2
  • 5
  • 18

2 Answers2

1

It was declared as public just to simplify the SDK developers life. But it never was expected to be called by outside developers. See also this post.

But if you really need to call this method, you can use reflection. Thought I suggest to look around for an alternative solution using official API.

alex2k8
  • 42,496
  • 57
  • 170
  • 221
  • Yes, after research I tried reflection, but as for these two APIs, the system complained a SecurityException that the app doesnt have INSTALL_PACKAGES permission. – user1105115 Dec 19 '11 at 05:34
  • and http://stackoverflow.com/questions/5803999/install-apps-silently-with-granted-install-packages-permission says the app should be signed with an official certificate which seems for now not testable and applicable. Sorry I cant edit the quick answer above so append it here. – user1105115 Dec 19 '11 at 05:42
1

In general you should not use "hidden" APIs in your applications. These methods are for internal usage and can be changed or even removed without notice. They are often not available for non-system applications due to permission restriction. If you want to use these APIs in your application then you may build your app within the platform build.

There is also a workaround to build application that uses hidden API in Eclipse: you can collect compiled framework libraries from the platform build and add them to build path as "User library", framework_intermediates/classes-full-debug.jar should be enough for the package manager.

Community
  • 1
  • 1
Darth Beleg
  • 2,657
  • 24
  • 26
  • Thank you very much for sharing this workaround, Darth. But a step forward and two steps backward. The SecurityException hinders the employment of these APIs. After research here and other sources, seems there is no way to programatically install files without user intervention. – user1105115 Dec 19 '11 at 05:46