码迷,mamicode.com
首页 > 移动开发 > 详细

Android 中的常用方法

时间:2016-01-26 12:08:31      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

//安装apk文件 

 

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

 

 

//卸载apk文件

 private void uninstallAPK(String packageName){
  Intent intent = newIntent(Intent.ACTION_VIEW);
  Uri data = Uri.parse("package:"+ packageName);
  intent.setData(data);
  startActivity(intent);
 }


 //编辑图片大小,保持图片不变形。
 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;
  //保持不变形
  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);
  //切图
  int x = (tmpWidth -resetWidth)/2;
  int y = (tmpHeight -resetHeight)/2;
  returnBitmap.createBitmap(sourceBitmap, x, y, resetWidth,resetHeight);
 }

 

//从SIM卡中获取联系人

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

Android 中的常用方法

标签:

原文地址:http://www.cnblogs.com/jettlee410/p/5159667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!