Common methods in Android

Source: Internet
Author: User

Install APK file

private void installapk (file file) {
Intent Intent = newintent (Intent.action_view);
Uri data =uri.fromfile (file);
String type = "Application/vnd.android.package-archive";
Intent.setdataandtype (Data,type);
StartActivity (Intent);
}

Uninstall APK file

private void uninstallapk (String packagename) {
Intent Intent = newintent (Intent.action_view);
Uri data = Uri.parse ("package:" + PackageName);
Intent.setdata (data);
StartActivity (Intent);
}


Edit the picture size to keep the picture from deforming.
public static Bitmap Resetimage (Bitmapsourcebitmap,int resetwidth,int resetheight) {
int width =sourcebitmap.getwidth ();
int height =sourcebitmap.getheight ();
int tmpwidth;
int tmpheight;
float ScaleWidth = (float) resetwidth/(float) width;
float ScaleHeight = (float) resetheight/(float) height;
float Maxtmpscale = scalewidth>= scaleheight? Scalewidth:scaleheight;
Keep Not deformed
Tmpwidth = (int) (Maxtmpscale *width);
Tmpheight = (int) (Maxtmpscale *height);
Matrix M = new Matrix ();
M.setscale (Maxtmpscale,maxtmpscale, Tmpwidth, tmpheight);
Sourcebitmap =bitmap.createbitmap (sourcebitmap, 0, 0, sourcebitmap.getwidth (), Sourcebitmap.getheight (), m, false);
Transduction
int x = (tmpwidth-resetwidth)/2;
int y = (tmpheight-resetheight)/2;
Returnbitmap.createbitmap (Sourcebitmap, x, Y, resetwidth,resetheight);
}

Get contacts from your SIM card

Private Cursor getcontacts () {
Uri uri = uri.parse ("Content://sim/adn");
string[] projection = new string[] {"Name", "Phone"};
String selection = null;
string[] Selectionargs = null;
String sortOrder = null;
Return Managedquery (URI, projection, selection, selectionargs,sortorder);
}

Common methods in Android

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.