android中的常用方法,Android 中的常用方法

//安装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);

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值