Objective
Finally saved an article, this series to practical, welcome and I share and recommend the use of code snippets ~ ~
Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com
Body
First, get the path where the APK has been installed
Packagemanager pm = Getpackagemanager ();
For (ApplicationInfo app:pm.getInstalledApplications (0)) {
LOG.D ("Packagelist", "Package:" + App.packagename + ", SourceDir:" + app.sourcedir);
}
The output is as follows:
Package:com.tmobile.thememanager, SourceDir:/system/app/thememanager.apk
Package:com.touchtype.swiftkey, SourceDir:/data/app/com.touchtype.swiftkey-1.apk
reproduced from here.
Second, multi-process preferences data sharing
public static void Putstringprocess (Context ctx, string key, String value) {
Sharedpreferences sharedpreferences = ctx.getsharedpreferences ("Preference_mu", context.mode_multi_process);
Editor editor = Sharedpreferences.edit ();
Editor.putstring (key, value);
Editor.commit ();
}
public static string Getstringprocess (Context ctx, string key, String defvalue) {
Sharedpreferences sharedpreferences = ctx.getsharedpreferences ("Preference_mu", context.mode_multi_process);
Return sharedpreferences.getstring (key, defvalue);
}
Related articles:
Http://zengrong.net/post/1687.htm
Iii. generic ArrayList-to-array
@SuppressWarnings ("Unchecked")
public static <T> t[] ToArray (class<?> cls, arraylist<t> items) {
if (items = = NULL | | items.size () = = 0) {
Return (t[]) array.newinstance (CLS, 0);
}
Return Items.toarray ((t[)) array.newinstance (CLS, Items.size ()));
}
Iv. Save Recovery ListView Current Location
private void Savecurrentposition () {
if (Mlistview! = null) {
int position = Mlistview.getfirstvisibleposition ();
View v = mlistview.getchildat (0);
int top = (v = = null)? 0:v.gettop ();
Save position and Top
}
}
private void Restoreposition () {
if (Mfolder! = NULL && Mlistview! = null) {
int position = 0;//Remove the saved data
int top = 0;//to remove saved data
Mlistview.setselectionfromtop (position, top);
}
}
can be saved in preference or in a database, and then set after the data is loaded.
V. Calling portable hotspot and data sharing settings
public static Intent gethotspotsetting () {
Intent Intent = new Intent ();
Intent.setaction (Intent.action_main);
componentname com = new ComponentName ("Com.android.settings", "com.android.settings.TetherSettings");
Intent.setcomponent (COM);
return intent;
}
Six, formatted output IP address
public static String GetIP (Context ctx) {
Return formatter.formatipaddress ((Wifimanager) Ctx.getsystemservice (context.wifi_service). GetConnectionInfo (). Getipaddress ());
}
Seven, folder sorting (first folder sorting, after file sorting)
public static void Sortfiles (file[] files) {
Arrays.sort (Files, new comparator<file> () {
@Override
public int Compare (file lhs, file rhs) {
A negative number indicates that O1 is less than O2, returning 0 means O1 and O2 are equal, and returning positive numbers means O1 is greater than O2.
Boolean L1 = Lhs.isdirectory ();
Boolean L2 = Rhs.isdirectory ();
if (L1 &&!l2)
return-1;
else if (!l1 && L2)
return 1;
else {
Return Lhs.getname (). CompareTo (Rhs.getname ());
}
}
});
}
Android Utility code seven paragraph (iii)