05/06 09:46:34: Launching app
$ adb shell am start -n “com.example.shiyan8/com.example.shiyan8.MainActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet…Waiting for process to come online
Connected to process 6781 on device emulator-5554
Capturing and displaying logcat messages from application. This behavior can be disabled in the “Logcat output” section of the “Debugger” settings page.
W/example.shiyan: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10087(com.example.shiyan8) identical 10 lines
W/example.shiyan: JIT profile information will not be recorded: profile file does not exits.
I/InstantRun: starting instant run server: is main process
W/example.shiyan: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/example.shiyan: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/OpenGLRenderer: HWUI GL Pipeline
D/: HostConnection::get() New Host Connection established 0xec35b700, tid 6799
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without…
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xec405360: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403690)
D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403690)
I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=790ms; Flags=0, IntendedVsync=1516971741026, Vsync=1517121741020, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1517128271500, AnimationStart=1517128370700, PerformTraversalsStart=1517129707500, DrawStart=1517130067100, SyncQueued=1517130177500, SyncStart=1517185717600, IssueDrawCommandsStart=1517186932800, SwapBuffers=1517804587300, FrameCompleted=1517818094200, DequeueBufferDuration=43000, QueueBufferDuration=191000,
I/OpenGLRenderer: Davey! duration=719ms; Flags=0, IntendedVsync=1517139751370, Vsync=1517773084678, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1517787427300, AnimationStart=1517787503300, PerformTraversalsStart=1517788113700, DrawStart=1517788474000, SyncQueued=1517791460200, SyncStart=1517818215400, IssueDrawCommandsStart=1517818315800, SwapBuffers=1517871967100, FrameCompleted=1517886337900, DequeueBufferDuration=1857000, QueueBufferDuration=688000,
D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403690)
I/example.shiyan: CollectorTransition concurrent copying GC freed 28391(5MB) AllocSpace objects, 1(20KB) LOS objects, 51% free, 1460KB/2MB, paused 5.433ms total 19.299ms
D/EGL_emulation: eglMakeCurrent: 0xec405360: ver 2 0 (tinfo 0xec403690)

解决方案 »

  1.   

    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;
    }
    }
    }
      

  2.   

     application may be doing too much work on its main thread.  不要在主线程中弄,重新启动一个线程