Android code block

Source: Internet
Author: User

1. Obtain the System Version Number:

PackageInfo info = this. getPackageManager (). getPackageInfo (this. getPackageName (), 0 );

Int versionCode = info. versionCode

String versionName = info. versionNam

2. Obtain system information:

String archiveFilePath = "sdcard/download/Law.apk"; // installation package path

PackageManager pm = getPackageManager ();

PackageInfo info = pm. getPackageArchiveInfo (archiveFilePath, PackageManager. GET_ACTIVITIES );

If (info! = Null ){

ApplicationInfo appInfo = info. applicationInfo;

String appName = pm. getApplicationLabel (appInfo). toString ();

String packageName = appInfo. packageName; // obtain the installation package name.

String version = info. versionName; // obtain the version information.

Toast. makeText (test4.this, "packageName:" + packageName + "; version:" + version, Toast. LENGTH_LONG). show ();

Drawable icon = pm. getApplicationIcon (appInfo); // get the icon Information

TextView TV = (TextView) findViewById (R. id. TV); // display icon

TV. setBackgroundDrawable (icon );
3. Obtain the installation path and list of installed programs

(1) obtain the current program path in android

GetApplicationContext (). getFilesDir (). getAbsolutePath ()

(2) android app list

List PackageInfoList = getPackageManager (). getInstalledPackages (0 );
4. Image Retrieval, application name, and package name

PackageManager pManager = MessageSendActivity. this. getPackageManager ();

List AppList = Utils. getAllApps (MessageSendActivity. this );

For (int I = 0; I

PackageInfo pinfo = appList. get (I );

Required iteminfo items item = new required iteminfo ();

// Set Icon

Using item. setIcon (pManager. getApplicationIcon (pinfo. applicationInfo ));
5. solve the problem that the Item itself cannot be clicked when there is a button on the item on the listview:

1. Add the code android: descendantFocusability = "blocksDescendants" to the item Attempt"

2. Add the code android: focusable = "true" to listview"

6. Do not enter Chinese characters in the text box:

Android: digits = "1234567890qwertyuiopasdfghjklzxcvbnm '-= [] \;,./~! @ # $ % ^ * () _ + }{:? & <> "'" Does not input Chinese characters.
7. Obtain the screen width and height
DisplayMetrics displayMetrics = new DisplayMetrics ();

This. getWindowManager (). getdefadisplay display (). getMetrics (displayMetrics );

Int height = displayMetrics. heightPixels;

Int width = displayMetrics. widthPixels;
8. Obtain the device model, SDK version, and system version.
String device_model = Build. MODEL; // Device MODEL

String version_sdk = Build. VERSION. SDK; // the sdk version of the device.

String version_release = Build. VERSION. RELEASE; // system VERSION of the device
9. obtain all the activities under the application.
Public static ArrayList GetActivities (Context ctx ){

ArrayList Result = new ArrayList ();

Intent intent = new Intent (Intent. ACTION_MAIN, null );

Intent. setPackage (ctx. getPackageName ());

For (ResolveInfo info: ctx. getPackageManager (). queryIntentActivities (intent, 0 )){

Result. add (info. activityInfo. name );

}

Return result;

}

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.