Skip to content

Commit

Permalink
update use system camera example with androidx
Browse files Browse the repository at this point in the history
  • Loading branch information
lingxiaoplus committed Mar 30, 2019
1 parent 1f06f73 commit 8ab77ab
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
Expand Down Expand Up @@ -59,7 +60,8 @@ public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果是7.0以上,使用FileProvider,否则会报错
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri imgUri = FileProvider.getUriForFile(getApplicationContext(), "com.camera.lingxiao.camerademo.fileProvider", it);
String authority = getApplicationInfo().packageName + ".fileProvider";
Uri imgUri = FileProvider.getUriForFile(getApplicationContext(), authority, it);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri); //设置拍照后图片保存的位置
} else {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(it)); //设置拍照后图片保存的位置
Expand All @@ -77,8 +79,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 200) {
Toast.makeText(this, "拍照成功", Toast.LENGTH_SHORT).show();
String authority = getApplicationInfo().packageName + ".fileProvider";
Uri imgUri = FileProvider.getUriForFile(getApplicationContext(),
"com.camera.lingxiao.camerademo.fileProvider", it);
authority, it);
gotoCrop(imgUri);
} else if (requestCode == 201) {
Bitmap bitmap = BitmapFactory.decodeFile(it.getAbsolutePath());
Expand Down

0 comments on commit 8ab77ab

Please sign in to comment.