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;
}