标签: android-camera-intent

在onActivityResult中使用相机时遇到问题

我有两个选项"选择照片"和"拍照" - 我的选择照片功能完全正常,但拍照时出现问题.主要是保存的图像在保存后显示在图像视图中.

定义了我的照片位置:

public class photoActivity extends Activity {   
      private String photoPath;
      private ImageView imgView;
{...} 
Run Code Online (Sandbox Code Playgroud)

我的相机听众:

bPicFromCam.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            String state = Environment.getExternalStorageState();

            if (Environment.MEDIA_MOUNTED.equals(state)) {

                long captureTime = System.currentTimeMillis();

                photoPath = Environment.getExternalStorageDirectory() + "/MYAPP" + captureTime + ".jpg";

                getPicFromCam(v);
            }
            else{

                Toast.makeText(getApplicationContext(),
                    "Sorry there is a problem accessing your SDCard, " +
                    "please select a picture from your gallery instead.", Toast.LENGTH_LONG).show();
            }

        }
    });
Run Code Online (Sandbox Code Playgroud)

然后我的代码启动相机意图(注意photoPath是正确的):

    public void getPicFromCam(View view){

    System.out.println("photoPath: " + …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-camera android-camera-intent

10
推荐指数
1
解决办法
2万
查看次数

Android 5.1.1默认摄像头在捕获图像后返回onActivityResult中的空意图

我有以下代码请求用户从照片应用程序中选择图像或通过相机应用程序捕获图像:

    // Camera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = fragment.getActivity().getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for(ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{})); …
Run Code Online (Sandbox Code Playgroud)

camera android android-intent android-camera-intent

10
推荐指数
1
解决办法
2710
查看次数

android android.provider.MediaStore.ACTION_VIDEO_CAPTURE使用nexus 7返回null onActivityResult

我正在使用录制视频的意图.

所以我在recordVideo按钮的单击上使用以下代码

Videofilepath = "";
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent,REQUEST_VIDEO_CAPTURED);
Run Code Online (Sandbox Code Playgroud)

在onActivityResult中

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
            case IMAGE_PICK:
                this.imageFromGallery(resultCode, data);
                break;
            case IMAGE_CAPTURE:
                this.imageFromCamera(resultCode, data);
                break;
            case REQUEST_VIDEO_CAPTURED:
                this.videoFromCamera(resultCode, data);

                break;
            default:
                break;
            }
        }
    }


private void videoFromCamera(int resultCode, Intent data) {
        uriVideo = data.getData();


        uploadedFileName="";
        Constant.IS_FILE_ATTACH = true;

        Toast.makeText(PDFActivity.this, uriVideo.getPath(), Toast.LENGTH_LONG)
        .show();
        String[] filePathColumn = { MediaStore.Video.Media.DATA };

        Cursor cursor = getContentResolver().query(uriVideo, filePathColumn,
                null, null, …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-camera-intent nexus-7

9
推荐指数
1
解决办法
1万
查看次数

Android:BroadcastReceiver意图检测相机拍照?

我正在开发一个Android应用程序,每次使用手机拍摄新图像时都需要执行操作.我不想在我的应用程序中拍摄图像,而是在Camera应用程序拍摄图像并将其保存到SD卡时执行某些操作.现在,我已经实现了一个正在侦听"android.intent.action.CAMERA_BUTTON"的BroadcastReceiver.但是,当我想要它时,似乎没有被调用.我试图在我自己的手机上使用BroadcastReceiver的OnReceive方法的第一行上的换行调试应用程序,但它从未达到该代码.

有谁知道我应该听的正确意图是什么?或者使用BroadcastReceiver甚至不是最好的方法吗?(例如,有没有更好的方法来实现这一点,例如在将新图像保存到卡时进行监听)?

谢谢!

更新:我的手机上有一个轨迹球(HTC Eris),因此拍照的方式是不是可以作为"相机按钮"发送?如果是这样,是否有一个没有"相机按钮"的手机的解决方法,而是像轨迹球?

android broadcastreceiver android-intent android-camera android-camera-intent

8
推荐指数
1
解决办法
1万
查看次数

android相机纵向方向

我在我的应用程序中使用相机.我只是intent用来启动相机

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(cameraIntent, 101);
Run Code Online (Sandbox Code Playgroud)

捕获的图像自动进入landscape view.如何camera捕获图像portrait view

android android-camera android-camera-intent landscape-portrait

8
推荐指数
1
解决办法
2万
查看次数

Android - 通过Intent拍摄照片并使用自定义名称将其保存到自定义目的地

我有一个程序通过Intent打开相机拍照.那部分工作已经很好了.但是,我希望它保存到具有特定文件名的某个文件夹(文件名是可选的,但它确实非常有帮助).

所以这就是我到目前为止所拥有的.

这是打开相机的代码行:

//TODO camera stuff.
Intent openCam = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

//The two lines of code below were commented out at first.
//They were eventually added when I tried to save it with a custom name and destination
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
openCam.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

startActivityForResult(openCam, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)

结果处理程序在这里:

//TODO handle result
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
   if (resultCode == RESULT_OK) {
         // Image captured and saved to fileUri …
Run Code Online (Sandbox Code Playgroud)

camera android android-sdcard android-camera-intent

8
推荐指数
2
解决办法
6万
查看次数

使用Intent以纵向模式打开相机

我能够从我打开设备的摄像头Activity使用Intent,如下所示:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = getOutputMediaFileUri();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
Run Code Online (Sandbox Code Playgroud)

我的问题是我Activity的设置为横向模式,因此当相机打开时,它也会以横向模式打开- 但我只需要在纵向模式下打开相机.

因此,请在使用Intent启动设备的相机时告诉我如何执行此操作.

谢谢...

android android-camera android-camera-intent

8
推荐指数
1
解决办法
6226
查看次数

Camera Intent没有返回调用Activity

我已经阅读了很多关于这个问题的问题.有些类似于我所经历的; 我没有成功地尝试了答案.该代码适用于HTC Android 4.2,不适用于Nexus 7 Android 4.4.我已经修改了存储目录以在android 4.4上工作,所以这不是问题.

如果我使用相机意图永远不会返回

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
Run Code Online (Sandbox Code Playgroud)

如果我使用,它会返回

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);
Run Code Online (Sandbox Code Playgroud)

但它不保存文件.

这是完整的代码.调用意图

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(manager) != null)
{
    try
    {
        final File photoFile = createImageFile();

        if (photoFile != null)
        {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            //takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);
            startActivityForResult(takePictureIntent, 1);
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

文件名

private File createImageFile() throws IOException
{
    if (mStorageDirectory == null)
    {
        createInitialStorageDirectory();
        setupFolders();
        mScrollList.notifyDataSetInvalidated();
    }

    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new …
Run Code Online (Sandbox Code Playgroud)

android photo android-intent android-camera-intent

8
推荐指数
2
解决办法
6108
查看次数

Android - 相机意图低位图质量

使用Android相机Intent拍照时,我得到的是低质量的位图图像.我想知道是否有可能使这个图像体面的质量.

我搜索了一些有关它的信息,我认为我必须使用'EXTRA_OUTPUT'(http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE)

我正在努力,因为我不知道放在哪里,我不知道它是否能解决我的问题.

按btnTakePhoto后,我改变布局并打开Android摄像头.位图以第二种布局(低质量)显示.这是我的代码:

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Camera extends AppCompatActivity {
    ImageButton btnTakePhoto;
    ImageView imgTakenPhoto;
    private static final int CAM_REQUEST = 1313;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.camera);

        btnTakePhoto = (ImageButton) findViewById(R.id.buttonFoto);
        imgTakenPhoto = (ImageView) findViewById(R.id.genomenFoto);


    btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());
}
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == CAM_REQUEST){
            setContentView(R.layout.share);
            Bitmap thumbnail = …
Run Code Online (Sandbox Code Playgroud)

android bitmap android-camera-intent

8
推荐指数
3
解决办法
2万
查看次数

当我选择任何第三方相机应用程序时,相机意图中的空指针异常

我的问题是,每次我选择第三方相机应用程序,例如Beauty Plus Camera我每次都有空指针异常,我的代码完全适用于默认的相机应用程序,它甚至可以与谷歌为摩托车系列手机制作的新相机配合使用.

第一次选择画廊或相机选项的对话框如下:

private void OpenDialogForImage() {

    final CharSequence[] items = {
            "Gallary", "Camera", "Cancel"
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            // Do something with the selection
            switch (item) {
                case 0:
                    Intent intent1 = new Intent(
                            Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent1.setType("image/*");
                    startActivityForResult(
                            Intent.createChooser(intent1, "Select File"),
                            SELECT_FILE);
                    break;
                case 1:

                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(intent, REQUEST_CAMERA);

                    break;
                case 2:

                    break;
            }
        }
    });
    AlertDialog alert = builder.create(); …
Run Code Online (Sandbox Code Playgroud)

camera android nullpointerexception android-intent android-camera-intent

8
推荐指数
1
解决办法
850
查看次数