现在的位置: 首页 > 综合 > 正文

Android中常用的函数

2014年02月11日 ⁄ 综合 ⁄ 共 1283字 ⁄ 字号 评论关闭

//安装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中常用的函数_挑戰者_新浪博客

抱歉!评论已关闭.