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

更多相关文章

  1. Android保持屏幕常亮的方法
  2. android播放音乐文件代码
  3. Android得到SD卡文件夹大小以及删除文件夹操作
  4. Android(安卓)ndk开发之在c文件里打印log
  5. Android(安卓)Studio常见错误及解决方法汇总
  6. Android实现振动效果
  7. 通用android studio gradle 文件(电商商家版,两个gradle不同)
  8. android 学习心得
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android 创建没有标题栏的对话框
  2. unity与android交互(1)
  3. Android property-animation 占CPU偏高
  4. Android Training - 使用IntentService执
  5. Android配置gradle 阿里云镜像
  6. Android SpannableString使用例子
  7. Android 加载图片并存放在缓存中
  8. Android自定义属性,format
  9. Android 代码监控apk安装,卸载,替换
  10. Android 实现蓝牙打印的功能