Call the "Application Info" interface of the android System

Source: Internet
Author: User

"Android system settings-> ApplicationsProgram-> Manage Applications "lists the installed applications in the system. Select one of the programs to go to the "Application
Information (Application
Info) interface. This interface displays the program name, version, storage, permissions, and other information, as well as buttons such as detaching, stopping, and clearing the cache. When writing related programs (such
You can call this panel, which naturally provides great convenience. So how to implement it?

This interface is provided in the latest Android SDK 2.3 (API level 9. In the document path

Docs/reference/Android/provider/settings.html # action_application_details_settings

There is a description like this:

Public static final string action_application_details_settingsSince: API level 9

Activity action: show screen of details about a special application.
In some cases, a matching activity may not exist, so ensure you safeguard against this.
Input:
The intent's data URI specifies the application package name to be
Shown, with the "package" scheme. That is "package: COM. My. app ".
Output: Nothing.
Constant Value: "android. settings. application_details_settings"

That is to say, we only needAndroid. provider. settings. action_application_details_settingsAs action;"Package: package name of the application"As Uri, you can use startactivity to start the application information interface.CodeAs follows:

View plain
    1. Intent intent =NewIntent (settings. action_application_details_settings );
    2. Uri uri = URI. fromparts (scheme, packagename,Null);
    3. Intent. setdata (URI );
    4. Startactivity (intent );

 

However, in versions earlier than Android 2.3, there is no public interface. By viewing the source code of the platform/packages/apps/settings. Git program set by the system, you can find that the application information interface is installedappdetails. Here (2.1) And here (2.2), we can see Android2.1 And Android2.2 (Management applications. Java) is how to start installedappdetails. View plain
  1. // Utility method used to start sub Activity
  2. Private VoidStartapplicationdetailsactivity (){
  3. // Create intent to start new activity
  4. Intent intent =NewIntent (intent. action_view );
  5. Intent. setclass (This, Installedappdetails.Class);
  6. Intent. putextra (app_pkg_name, mcurrentpkgname );
  7. // Start new activity to display extended information
  8. Startactivityforresult (intent, installed_app_details );
  9. }
But constant App_pkg_nameIs not the same. "PKG" is defined in 2.2, and "com. Android. settings. applicationpkgname" is defined in 2.1" So, For versions 2.1 and earlier In this way, we can call installedappdetails: view plain
    1. Intent I =NewIntent (intent. action_view );
    2. I. setclassname ("Com. Android. Settings","Com. Android. settings. installedappdetails");
    3. I. putextra ("Com. Android. settings. applicationpkgname", Packagename );
    4. Startactivity (I );
For 2.2, you only need to replace the first parameter of putextra above with "PKG" In summary, the common code for calling "application information" is as follows: View plain
  1. Private Static FinalString scheme ="Package";
  2. /** 
  3. * The extra name required to call the system installedappdetails interface (for Android 2.1 and earlier versions) 
  4. */
  5. Private Static FinalString app_pkg_name_21 ="Com. Android. settings. applicationpkgname";
  6. /** 
  7. * The extra name required to call the system installedappdetails interface (for Android 2.2) 
  8. */
  9. Private Static FinalString app_pkg_name_22 ="PKG";
  10. /** 
  11. * Package name of installedappdetails 
  12. */
  13. Private Static FinalString app_details_package_name ="Com. Android. Settings";
  14. /** 
  15. * Installedappdetails Class Name 
  16. */
  17. Private Static FinalString app_details_class_name ="Com. Android. settings. installedappdetails";
  18. /** 
  19. * Call the installedappdetails interface to display the details of the installed application. For Android 2.3 (API level 
  20. * 9) above, use the interfaces provided by the SDK; 2.3 or below, use non-public interfaces (view the source code of installedappdetails ). 
  21. * @ Param Context 
  22. * @ Param packagename 
  23. * Application package name 
  24. */
  25. Public Static VoidShowinstalledappdetails (context, string packagename ){
  26. Intent intent =NewIntent ();
  27. Final IntApilevel = build. version. sdk_int;
  28. If(Apilevel> =9){// 2.3 (apilevel 9) or above, use the interface provided by the SDK
  29. Intent. setaction (settings. action_application_details_settings );
  30. Uri uri = URI. fromparts (scheme, packagename,Null);
  31. Intent. setdata (URI );
  32. }Else{// Use a non-public interface below 2.3 (view the source code of installedappdetails)
  33. // In 2.2 and 2.1, installedappdetails uses different app_pkg_name.
  34. FinalString apppkgname = (apilevel =8? App_pkg_name_22
  35. : App_pkg_name_21 );
  36. Intent. setaction (intent. action_view );
  37. Intent. setclassname (app_details_package_name,
  38. App_details_class_name );
  39. Intent. putextra (apppkgname, packagename );
  40. }
  41. Context. startactivity (intent );
  42. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.