Skip to content

Commit

Permalink
增加crash异常捕获
Browse files Browse the repository at this point in the history
  • Loading branch information
AnliaLee committed Sep 4, 2018
1 parent 2b68915 commit 66a2a3a
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 324 deletions.
Binary file modified .gradle/4.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.1/taskHistory/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/4.1/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.1/taskHistory/taskHistory.lock
Binary file not shown.
606 changes: 295 additions & 311 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 11
versionName "1.1.8"
versionCode 12
versionName "1.1.9"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Map;

import static com.anlia.photofactory.factory.PhotoFactory.ERROR_CAMERA_NOT_FOUND;
import static com.anlia.photofactory.factory.PhotoFactory.ERROR_PICK_NOT_FOUND;
import static com.anlia.photofactory.factory.PhotoFactory.TYPE_PHOTO_CROP;
import static com.anlia.photofactory.factory.PhotoFactory.TYPE_PHOTO_FROM_GALLERY;

Expand Down Expand Up @@ -83,23 +84,31 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

switch (intent.getIntExtra(KEY_JOB, 0)) {
case JOB_SELECT_PHOTO_FROM_GALLERY:
requestIntent.setType("image/*");// 设置文件类型
requestIntent.setAction(Intent.ACTION_PICK);
requestIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(requestIntent, TYPE_PHOTO_FROM_GALLERY);
try {
requestIntent.setType("image/*");// 设置文件类型
requestIntent.setAction(Intent.ACTION_PICK);
requestIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(requestIntent, TYPE_PHOTO_FROM_GALLERY);
} catch (Exception e) {
e.printStackTrace();
if (mActivityResultListener != null) {
mActivityResultListener.onResultCallback(0, 0, null, ERROR_PICK_NOT_FOUND);
}
finish();
}
break;
case JOB_SELECT_PHOTO_FROM_CAMERA:
try {
requestIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(requestIntent, intent.getIntExtra(KEY_REQUEST, -99));
} catch (Exception e) {
e.printStackTrace();
if (mActivityResultListener != null) {
mActivityResultListener.onResultCallback(0, 0, null, ERROR_CAMERA_NOT_FOUND);
}
finish();
}
break;

case JOB_CROP_PHOTO:
requestIntent.setAction("com.android.camera.action.CROP");
requestIntent.putExtra("crop", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class PhotoFactory {
public static final String ERROR_MEDIA_INSERT_IMAGE = "ERROR_MEDIA_INSERT_IMAGE";//插入图片异常,通常发生在手机存储空间不足或存储空间被占用的情况
public static final String ERROR_MEDIA_GET_BITMAP = "ERROR_MEDIA_GET_BITMAP";//获取bitmap异常,通常发生在通过uri查找不到对应照片的情况
public static final String ERROR_COMPRESS = "ERROR_COMPRESS";//压缩图片异常,通常发生在某些配置较低的机型内存不足的情况
public static final String ERROR_PICK_NOT_FOUND = "ERROR_PICK_NOT_FOUND";//启动系统相册失败

public PhotoFactory(Context context){
this(context, Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+ "DCIM" +File.separator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public static Bitmap ScaleCompressFormUri(Context context, Uri uri, float newW,
} catch (OutOfMemoryError e) {
e.printStackTrace();
bitmap = ScaleCompressFormUri(context, uri, newW/2, newH/2);
} catch (Exception e) {
e.printStackTrace();
}
}
return bitmap;
Expand Down Expand Up @@ -116,10 +118,15 @@ public static Bitmap ScaleCompressFormBitmap(Context context, Bitmap bitmap, flo
* @throws IOException
*/
public static Bitmap QualityCompressFromUri(Context context, Uri uri, int targetSize) throws IOException {
InputStream input = context.getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(input);
input.close();
return QualityCompressFromBitmap(bitmap, targetSize);
try {
InputStream input = context.getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(input);
input.close();
return QualityCompressFromBitmap(bitmap, targetSize);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public static Uri GetUriForCrop(Context context, Uri uri) {
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, options);
} catch (FileNotFoundException e) {
} catch (Exception e) {
e.printStackTrace();
return null;
}

AssetFileDescriptor fileDescriptor = null;
Expand All @@ -59,8 +60,9 @@ public static Uri GetUriForCrop(Context context, Uri uri) {
try {
bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options);
fileDescriptor.close();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
return null;
} catch (OutOfMemoryError e) {
e.printStackTrace();
return null;
Expand Down

0 comments on commit 66a2a3a

Please sign in to comment.