}
catch (Exception e)
{
}
}
out.write(content);
out.flush();
out.close();
return true;
}
catch (Exception e)
{
return false;
}
}
**4.drawable转Bitmap**
private Bitmap drawableToBitmap(Drawable drawable) {
int dw = drawable.getIntrinsicWidth();
int dh = drawable.getIntrinsicHeight();
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
Bitmap bitmap=Bitmap.createBitmap(dw, dh, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, dw, dh);
drawable.draw(canvas);
return bitmap;
}
**5.调用系统拨号**
有2种方式
第一种:没有拨号界面,直接拨号
Uri uri=Uri.parse(“tel:”+“13012345678”);
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);// ACTION_CALL直接拨出
intent.setData(uri);
startActivity(intent);
第二种:拨号界面了,号码也输入好了,但是要手动点击拨号
Uri uri=Uri.parse(“tel:”+“13012345678”);
Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(uri);
startActivity(intent);
当然,不要忘了要加上权限
**6.调用系统短信界面**
第一种,设定发送的号码,和内容,界面没有联系人,群组组等按钮
Uri smsToUri = Uri.parse("smsto:13012345678");// 联系人地址
Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO,
smsToUri);
mIntent.putExtra("sms_body", "短信内容test123");// 短信内容
startActivity(mIntent);
效果如下:
**![](https://img-blog.csdn.net/20160708114721248?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
**
第二种,设定发送短信内容,不设置发送的号码,界面有联系人,群组等按钮
Uri smsUri = Uri.parse(“smsto:”);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra(“sms_body”, “短信内容”);
intent.setType(“vnd.android-dir/mms-sms”);
startActivity(intent);
**7.调用系统浏览器浏览网页**
Uri uri = Uri.parse(“http://www.baidu.com”);
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
**8.FileUtil工具类**
主要包括:在指定的位置创建指定的文件;在指定的位置创建文件夹;删除指定的文件;删除指定的文件夹;复制文件/文件夹;移动指定的文件(夹)到目标文件(夹)。
/**
- 文件操作工具类
*/
public class FileUtil {
/**
* 在指定的位置创建指定的文件
*
* @param filePath 完整的文件路径
* @param mkdir 是否创建相关的文件夹
* @throws Exception
*/
public static void mkFile(String filePath, boolean mkdir) throws Exception {
File file = new File(filePath);
file.getParentFile().mkdirs();
file.createNewFile();
file = null;
}
/**
* 在指定的位置创建文件夹
*
* @param dirPath 文件夹路径
* @return 若创建成功,则返回True;反之,则返回False
*/
public static boolean mkDir(String dirPath) {
return new File(dirPath).mkdirs();
}
/**
* 删除指定的文件
*
* @param filePath 文件路径
*
* @return 若删除成功,则返回True;反之,则返回False
*
*/
public static boolean delFile(String filePath) {
return new File(filePath).delete();
}
/**
* 删除指定的文件夹
*
* @param dirPath 文件夹路径
* @param delFile 文件夹中是否包含文件
* @return 若删除成功,则返回True;反之,则返回False
*
*/
public static boolean delDir(String dirPath, boolean delFile) {
if (delFile) {
File file = new File(dirPath);
if (file.isFile()) {
return file.delete();
} else if (file.isDirectory()) {
if (file.listFiles().length == 0) {
return file.delete();
} else {
int zfiles = file.listFiles().length;
File[] delfile = file.listFiles();
for (int i = 0; i < zfiles; i++) {
if (delfile[i].isDirectory()) {
delDir(delfile[i].getAbsolutePath(), true);
}
delfile[i].delete();
}
return file.delete();
}
} else {
return false;
}
} else {
return new File(dirPath).delete();
}
}
/**
* 复制文件/文件夹 若要进行文件夹复制,请勿将目标文件夹置于源文件夹中
* @param source 源文件(夹)
* @param target 目标文件(夹)
* @param isFolder 若进行文件夹复制,则为True;反之为False
* @throws Exception
*/
public static void copy(String source, String target, boolean isFolder)
throws Exception {
if (isFolder) {
(new File(target)).mkdirs();
File a = new File(source);
String[] file = a.list();
File temp = null;
for (int i = 0; i < file.length; i++) {
if (source.endsWith(File.separator)) {
temp = new File(source + file[i]);
} else {
temp = new File(source + File.separator + file[i]);
}
if (temp.isFile()) {
FileInputStream input = new FileInputStream(temp);
FileOutputStream output = new FileOutputStream(target + "/" + (temp.getName()).toString());
byte[] b = new byte[1024];
int len;
while ((len = input.read(b)) != -1) {
output.write(b, 0, len);
}
output.flush();
output.close();
input.close();
}
if (temp.isDirectory()) {
copy(source + "/" + file[i], target + "/" + file[i], true);
}
}
} else {
int byteread = 0;
File oldfile = new File(source);
if (oldfile.exists()) {
InputStream inStream = new FileInputStream(source);
File file = new File(target);
file.getParentFile().mkdirs();
file.createNewFile();
FileOutputStream fs = new FileOutputStream(file);
byte[] buffer = new byte[1024];
while ((byteread = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
}
}
}
/**
* 移动指定的文件(夹)到目标文件(夹)
* @param source 源文件(夹)
* @param target 目标文件(夹)
* @param isFolder 若为文件夹,则为True;反之为False
* @return
* @throws Exception
*/
public static boolean move(String source, String target, boolean isFolder)
throws Exception {
copy(source, target, isFolder);
if (isFolder) {
return delDir(source, true);
} else {
return delFile(source);
}
}
}
**9.获取sdk版本号**
public static int getAndroidSDKVersion(){
int version;
version = Integer.valueOf(android.os.Build.VERSION.SDK);
return version;
}
**10.存储bitmap到指定路径**
/**
* bitmap存储
* @param mBitmap
* @param strPath
*/
public static void saveMyBitmap(Bitmap mBitmap, String strPath,boolean isRecycle)
{
if(mBitmap!=null&&!mBitmap.isRecycled()&&!TextUtils.isEmpty(strPath))
{
File f = new File( strPath );
if (f.exists())
{
f.delete();
}
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mBitmap.compress(Bitmap.CompressFormat.JPEG, 60, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}catch (NullPointerException e)
{
e.getMessage();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
if(!mBitmap.isRecycled()&&isRecycle)
{
mBitmap.recycle();
System.gc();
}
}
}
**11.根据原图绘制圆形头像**
/**
* 根据原图和宽度保存圆形图片
*
* @param strPath
* @return
*/
public static Bitmap SaveCircleImage(String strPath)
{
Bitmap source = null;
try
{
source=Util.getLocalBitmap(strPath,true);
if(source != null)
{
final Paint paint = new Paint();
paint.setAntiAlias(true);
int iWidth = source.getWidth();
int iHeight = source.getHeight();
float fRate = 1.0f;
if (iWidth > 800 || iHeight > 800)
{
int iSetWidth = iWidth;
int iSetHeight = iHeight;
while(iSetWidth > 800 || iSetHeight > 800)
{
fRate = fRate - 0.01f;
iSetWidth = (int)(iWidth * fRate);
iSetHeight = (int)(iHeight * fRate);
}
}
iWidth = (int)(iWidth*fRate);
iHeight = (int)(iHeight*fRate);
Matrix matrix = new Matrix();
matrix.postScale(fRate,fRate); //长和宽缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
int min = iWidth;
if (iHeight < iWidth)
{
min = iHeight;
}
Bitmap target = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_4444);
/**
* 产生一个同样大小的画布
*/
Canvas canvas = new Canvas(target);
/**
* 首先绘制圆形
*/
canvas.drawCircle(min / 2, min / 2, min / 2, paint);
/**
* 使用SRC_IN
*/
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
/**
* 绘制图片
*/
Rect srcRc = new Rect(0, 0, iWidth, iHeight);
Rect dstRc = new Rect(0, 0, min, min);
if (iHeight < iWidth)
{
srcRc.left = (iWidth - iHeight)/2;
srcRc.right = srcRc.left + iHeight;
}
else
{
srcRc.top = (iHeight - iWidth)/2;
srcRc.bottom = srcRc.top + iWidth;
}
canvas.drawBitmap(resizeBmp, srcRc, dstRc, paint);
if(!source.isRecycled())
{
source.recycle();
System.gc();
}
if(!resizeBmp.isRecycled())
{
resizeBmp.recycle();
System.gc();
}
Bitmap bmSave = GetWhiteBkPng(target, min);
saveMyBitmap(bmSave, strPath);
return target;
}
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return null;
}
**12.根据原图片,绘制灰色图片,类似qq人物头像不在线**
/**
* 将彩色图转换为灰度图
* @param img 位图,img不可以回收
尾声
最后,我再重复一次,如果你想成为一个优秀的 Android 开发人员,请集中精力,对基础和重要的事情做深度研究。
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。 整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。
最后想要拿高薪实现技术提升薪水得到质的飞跃。最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以为了大家能够顺利进阶中高级、架构师,我特地为大家准备了一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。
当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。
进阶学习视频
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
收
尾声
最后,我再重复一次,如果你想成为一个优秀的 Android 开发人员,请集中精力,对基础和重要的事情做深度研究。
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。 整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。
最后想要拿高薪实现技术提升薪水得到质的飞跃。最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以为了大家能够顺利进阶中高级、架构师,我特地为大家准备了一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。
当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。
进阶学习视频
[外链图片转存中…(img-fGk3Fask-1714414171237)]
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
[外链图片转存中…(img-DuqZG6nt-1714414171238)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!