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);
}
禁用后退键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
return true;
}
return super.onKeyDown(keyCode, event);
}
Android 中的常用方法的更多相关文章
- android开发(32) android 中 actionbar 常用方法。设置标题,隐藏图标等
设置标题: actionBar.setTitle("关于我们"); 使返回箭头出现 actionBar.setDisplayHomeAsUpEnabled(true); 监听返回按 ...
- Android 中常见控件的介绍和使用
1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...
- Android中SQLite应用详解
上次我向大家介绍了SQLite的基本信息和使用过程,相信朋友们对SQLite已经有所了解了,那今天呢,我就和大家分享一下在Android中如何使用SQLite. 现在的主流移动设备像Android.i ...
- Android中Intent组件详解
Intent是不同组件之间相互通讯的纽带,封装了不同组件之间通讯的条件.Intent本身是定义为一个类别(Class),一个Intent对象表达一个目的(Goal)或期望(Expectation),叙 ...
- Android中SQLite应用详解(转)
上次我向大家介绍了SQLite的基本信息和使用过程,相信朋友们对SQLite已经有所了解了,那今天呢,我就和大家分享一下在Android中如何使用SQLite. 现在的主流移动设备像Android.i ...
- Android中FTP服务器、客户端搭建以及SwiFTP、ftp4j介绍
本文主要内容: 1.FTP服务端部署---- 基于Android中SwiFTP开源软件介绍: 2.FTP客户端部署 --- 基于ftp4j开源jar包的客户端开发 : 3.使用步骤 --- 如何测试我 ...
- Android中滑屏实现----手把手教你如何实现触摸滑屏以及Scroller类详解
前言: 虽然本文标题的有点标题党的感觉,但无论如何,通过这篇文章的学习以及你自己的实践认知,写个简单的滑屏小 Demo还是just so so的. 友情提示: 在继续往下面读之前,希望您对以下知识点 ...
- Android中的几种多线程实现
有以下几种方式: 1)Activity.runOnUiThread(Runnable) 2)View.post(Runnable) ;View.postDelay(Runnable , long) 3 ...
- Android中获取系统内存信息以及进程信息-----ActivityManager的使用(一)
本节内容主要是讲解ActivityManager的使用,通过ActivityManager我们可以获得系统里正在运行的activities,包括 进程(Process)等.应用程序/包.服务(Serv ...
随机推荐
- requirejs加载css样式表
1. 在 https://github.com/guybedford/require-css 下载到require-css包 2. 把css.js或者css.min.js复制到项目的js目录下 3. ...
- 通过nginx代理之后,获取客户端ip
1.相关nginx配置(通过header将客户端ip,host等信息传入) location ~ .*.do$ { proxy_set_header X-Real-IP $remote_addr; p ...
- ES6 对象增强和结构赋值
The enhanced Object literals: ES6 has added some new syntax-based extensions to {} object literal fo ...
- ROWID伪列
ROWID伪列概念: 在数据表中每一行所保存的记录,oracle会为每条记录分配一个唯一的地址编号,这个编号就是通过ROWID表示的. 所有的数据都利用ROWID进行定位. 观察rowid的存在 SQ ...
- position之fixed固定定位、absolute绝对定位和relative相对定位
什么是层模型? 什么是层布局模型?层布局模型就像是图像软件PhotoShop中非常流行的图层编辑功能一样,每个图层能够精确定位操作,但在网页设计领域,由于网页大小的活动性,层布局没能受到热捧.但是在网 ...
- mysql:SQL语句操作数据库中表和字段的COMMENT值
转载:http://blog.163.com/inflexible_simple/blog/static/167694684201182601221758/ 参考文档不太给力啊,表注释和字段注释的资料 ...
- BWT压缩算法(Burrows-Wheeler Transform)
参考: BWT (Burrows–Wheeler_transform)数据转换算法 压缩技术主要的工作方式就是找到重复的模式,进行紧密的编码. BWT(Burrows–Wheeler_transfor ...
- String or binary data would be truncated 解决办法
原因: 一般出现这个问题是因为数据库中的某个字段的长度小,而插入数据大 解决: 找到相应字段,修改表结构,使表字段大小相同或大于要插入的数据
- 打开hibernate文件报警告
在web工程中新建一个,Hibetnate项目,打开配置文件报警高错误,This project is not a MyEclipse Hiberbate Project. Assuming Hibe ...
- RDLC开发笔记
1.当报表中使用FormatPercent求百分数时,若分母有小数,务必使用CDbl将其转为double类型,否则会报“错误号”.