2017-09-13 64 views
0

我需要該程序點擊平板電腦上的Android相機按鈕,這是我的代碼,它工作正常,但我需要它通過程序完成; 非常感謝。以編程方式點擊按鈕相機Android

private void sacoFotoIngresoLocal() { 

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    // Ensure that there's a camera activity to handle the intent 
    if (takePictureIntent.resolveActivity(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) { 
      Uri photoURI = FileProvider.getUriForFile(this,"com.example.android.fileprovider", photoFile); 
      takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); 
      startActivityForResult(takePictureIntent, REQUERIMEINTO_TOMAR_FOTO); 

     } 
    } 
} 

回答

0

在大多數設備(包括大多數平板電腦)上沒有「照相機按鈕」。此外,出於明顯的安全原因,您不能僞造用戶輸入(硬件或軟件)。

如果您想在沒有用戶介入的情況下拍攝照片,請直接使用相機API,或使用包裝它們的第三方庫(例如CameraKit-Android,Fotoapparat)。

相關問題