Android中常用的函数

//安装apk文件 

private void installAPK(File file) {
  Intent intent = new Intent(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 = new Intent(Intent.ACTION_VIEW);
  Uri data = Uri.parse("package:" + packageName);
  intent.setData(data);
  startActivity(intent);
 }


  //编辑图片大小,保持图片不变形。
 public static Bitmap resetImage(Bitmap sourceBitmap,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;
  return Bitmap.createBitmap(sourceBitmap, x, y, resetWidth, resetHeight);
 }

 

来源:(http://blog.sina.com.cn/s/blog_3f7f41d40100ipha.html ) - Android中常用的函数_挑戰者_新浪博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值