2017-08-08 133 views
-1

我已经在6.0上的Android Studio中使用模拟器获得了上述崩溃,但没有在使用6.0.1的设备上崩溃。模拟器有时会启动相机,但它大部分在logcat中没有任何事情崩溃,以指向正确的方向。有没有人有任何线索可能会发生什么?不幸的是相机已经停止了错误android 6.0.0

此外,这是一个当它通过时通过的图像。 Image_capture_camera

private File createImageFile() throws IOException 
{ 
    // Create an image file name 
    String timeStamp = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss").format(new Date()); 
    String imageFileName = "" + timeStamp; 
    File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); 
    File image = File.createTempFile(
      imageFileName, /* prefix */ 
      ".jpg",   /* suffix */ 
      storageDir  /* directory */ 
    ); 

    Name = imageFileName; 
    // Save a file: path for use with ACTION_VIEW intents 
    mCurrentPhotoPath = image.getAbsolutePath(); 
    return image; 
} 

private void dispatchTakePictureIntent() 
{ 
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    // Ensure that there's a camera activity to handle the intent 
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) 
    { 
     // Create the File where the photo should go 
     File photoFile = null; 
     try 
     { 
      photoFile = createImageFile(); 
     } 
     catch (IOException ex) 
     { 
      // Error occurred while creating the File 
     } 
     // Continue only if the File was successfully created 
     if (photoFile != null) 
     { 
      photoURI = FileProvider.getUriForFile(getActivity(), 
        "com.full.jusuf.snaphealth.fileprovider", 
        photoFile); 
      takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); 
      startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); 
     } 
    } 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) 
    { 

     final Uri uri = photoURI; 
     uri_data.add(new Timeline_Model(uri.toString(), Name)); 

     //save data to firebase 
     FirebaseStorage storage = FirebaseStorage.getInstance(); 
     StorageReference storageRef = storage.getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()); 
     storageRef.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child(Name).putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { 
      @Override 
      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) 
      { 
       String uri1 = taskSnapshot.getDownloadUrl().toString(); 
       FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 
       DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference(); 
       if (user != null) 
       { 
        long Count = System.currentTimeMillis(); 
        databaseReference.child("users").child(user.getUid()).child("image_uri").child("image" + Count).setValue(new Timeline_Model(uri1, Name)); 
       } 
      } 
     }); 

     PopulateGallery(); 
    } 
} 

的logcat:

08-08 02:22:26.576 17275-17330/com.full.jusuf.snaphealth V/FA: Recording user engagement, ms: 10526 
08-08 02:22:26.576 17275-17330/com.full.jusuf.snaphealth V/FA: Using measurement service 
08-08 02:22:26.576 17275-17330/com.full.jusuf.snaphealth V/FA: Connecting to remote service 
08-08 02:22:26.580 17275-17330/com.full.jusuf.snaphealth D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=10526, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=4121746325476785971}] 
08-08 02:22:26.593 17275-17330/com.full.jusuf.snaphealth V/FA: Using measurement service 
08-08 02:22:26.593 17275-17330/com.full.jusuf.snaphealth V/FA: Connection attempt already in progress 
08-08 02:22:26.593 17275-17330/com.full.jusuf.snaphealth V/FA: Activity paused, time: 917202 
08-08 02:22:26.611 17275-17330/com.full.jusuf.snaphealth D/FA: Connected to remote service 
08-08 02:22:26.611 17275-17330/com.full.jusuf.snaphealth V/FA: Processing queued up service tasks: 2 
08-08 02:22:26.678 17275-17357/com.full.jusuf.snaphealth D/EGL_emulation: eglMakeCurrent: 0x7f9ce78225e0: ver 3 1 (tinfo 0x7f9cdb3c2d40) 
08-08 02:22:26.679 17275-17357/com.full.jusuf.snaphealth E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f9cdb6c53e0 
+0

您必须添加当您的应用在6.0上运行时,相机的运行时权限。 –

回答

0

正如你可能知道,Android的23改权限策略完全,所以如果你的目标23+(或最新的,你可能会做)很可能你的问题是在这里

File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); 
File image = File.createTempFile(
     imageFileName, /* prefix */ 
     ".jpg",   /* suffix */ 
     storageDir  /* directory */ 
); 

或这里

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

(阅读:Android M Camera Intent + permission bug?

请确保您有

< uses-permission android:name="android.permission.CAMERA" /> 

< uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

在你的清单,然后去设置 - >应用程序 - > yourApp - >权限,确保存储和摄像头进行检查。如果您的崩溃不再使用手动设置的权限进行复制,请继续阅读 https://developer.android.com/training/permissions/requesting.html 并向您的应用程序使用的所有功能添加运行时权限请求。

+0

感谢您的回复,但它没有奏效。手动设置权限做同样的事情。奇怪的是,在模拟器上启动相机应用程序,但显示与上面链接的图像相同的图形故障。 – jusuf

+0

可能是一些硬件问题,然后,创建另一个模拟器随机设置不同,并设置相机模拟,而不是webcamN你现在可能已经重试。 – Nick

+0

我在仿真相机的新仿真器上遇到同样的问题。 – jusuf

0

我这个挣扎了很久,然后看到在Android API 23和高达你需要请求运行权限,在Android文档阅读Runtime Permissions,它应该解决您的问题

+0

没有这样的运气,它工作正常,除了nexus 5 6.0.1和6.0 API 23上的模拟器测试的每个设备上。我测试过的硬件包括s8和注5运行6.0.1和7.0,没有问题。我似乎无法追查原因。 – jusuf