为什么我的provider返回的是空值
代码粉 2019-05-06 11:16:52 package com.example.shiyan8;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
public static final int TAKE_PHOTO = 1;
private ImageView picture;
private Uri imageUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button take_photo = (Button) findViewById(R.id.take_photo);
picture = (ImageView) findViewById(R.id.picture);
take_photo.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
File outputImage = new File(getExternalCacheDir(),
“output_image.jpg”);
try{
if (outputImage.exists()){
outputImage.delete();
}
outputImage.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= 24) {
imageUri = FileProvider.getUriForFile(MainActivity.this,
“com.example.shiyan8.fileprovider”,outputImage);
} else {
imageUri = Uri.fromFile(outputImage);
}
Intent intent = new Intent(“android.media.action.IMAGE_CAPTURE”);
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent,TAKE_PHOTO);
}
});
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
switch (requestCode) {
case TAKE_PHOTO:
if (requestCode == RESULT_OK) {
try{
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
picture.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
break;
default:
break;
}
}
}
这是我的日志
2019-05-06 10:54:24.990 7419-7419/? I/example.shiyan: Not late-enabling -Xcheck:jni (already on)
2019-05-06 10:54:25.105 7419-7419/? W/example.shiyan: Unexpected CPU variant for X86 using defaults: x86
2019-05-06 10:54:25.767 7419-7419/com.example.shiyan8 W/example.shiyan: JIT profile information will not be recorded: profile file does not exits.
2019-05-06 10:54:25.769 7419-7419/com.example.shiyan8 I/chatty: uid=10087(com.example.shiyan8) identical 10 lines
2019-05-06 10:54:25.775 7419-7419/com.example.shiyan8 W/example.shiyan: JIT profile information will not be recorded: profile file does not exits.
2019-05-06 10:54:25.822 7419-7419/com.example.shiyan8 I/InstantRun: starting instant run server: is main process
2019-05-06 10:54:26.257 7419-7419/com.example.shiyan8 W/example.shiyan: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-05-06 10:54:26.258 7419-7419/com.example.shiyan8 W/example.shiyan: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-05-06 10:54:26.323 7419-7419/com.example.shiyan8 D/OpenGLRenderer: HWUI GL Pipeline
2019-05-06 10:54:26.397 7419-7441/com.example.shiyan8 I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-05-06 10:54:26.399 7419-7441/com.example.shiyan8 I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-05-06 10:54:26.400 7419-7441/com.example.shiyan8 I/OpenGLRenderer: Initialized EGL, version 1.4
2019-05-06 10:54:26.402 7419-7441/com.example.shiyan8 D/OpenGLRenderer: Swap behavior 1
2019-05-06 10:54:26.404 7419-7441/com.example.shiyan8 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without…
2019-05-06 10:54:26.404 7419-7441/com.example.shiyan8 D/OpenGLRenderer: Swap behavior 0
2019-05-06 10:54:26.422 7419-7441/com.example.shiyan8 D/EGL_emulation: eglCreateContext: 0xec405360: maj 2 min 0 rcv 2
2019-05-06 10:54:26.462 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 10:54:26.578 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:13.991 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:25.954 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:31.799 7419-7441/com.example.shiyan8 I/OpenGLRenderer: Davey! duration=1152ms; Flags=2, IntendedVsync=2812437912774, Vsync=2812437912774, OldestInputEvent=0, NewestInputEvent=0, HandleInputStart=2812437912774, AnimationStart=2812437912774, PerformTraversalsStart=2812437912774, DrawStart=2812437912774, SyncQueued=2812451718200, SyncStart=2812451795600, IssueDrawCommandsStart=2812471354900, SwapBuffers=2813565789400, FrameCompleted=2813590707400, DequeueBufferDuration=79000, QueueBufferDuration=223000,
2019-05-06 11:03:31.820 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:03:42.538 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:09.046 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:19.975 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:33.822 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
2019-05-06 11:04:42.054 7419-7441/com.example.shiyan8 D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403670)
---------------------
作者:qq_43620227
来源:CSDN
原文:https://blog.csdn.net/qq_43620227/article/details/89878402
版权声明:本文为博主原创文章,转载请附上博文链接!