我的相机应用程序在 Samsung Galaxy S 中给出空值

发布于 2024-12-10 03:52:19 字数 437 浏览 3 评论 0原文

我开发了一个带有默认相机的相机应用程序。此应用程序适用于所有其他 Android 手机,但三星 Galaxy S 存在一些问题

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

此代码给出了结果,我得到了一个位图图像。但我无法从中检索图像路径。

当我给出 EXTRA_OUTPUT 时,Galaxy S 返回空值。这样我就无法在调用相机意图之前定义文件路径和名称。当我们使用此应用程序拍照时,Galaxy S 会将这张照片保存在默认位置,而不是保存到预定义位置。

如果有人对此有解决方案,请帮助我。

I have developed a camera application with default camera. This application works in all other Android phones but some problem with Samsung Galaxy S

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

This code is giving a result and I am getting a bitmap image. But I couldn't retrieve an image path from this.

When I give EXTRA_OUTPUT, Galaxy S returning a null value. So that I couldn't define file path and name before calling camera intent. When we take picture using this application, Galaxy S is saving this picture in default location and not saving to pre defined location.

If anybody has solution for this, please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-12-17 03:52:19

我为此所做的是将 EXTRA_OUTPUT 的位置定义为 Uri,将其缓存在静态或成员变量中,然后在 onActivity 结果中使用缓存的位置来检索图像。我遇到了你所描述的同样的问题,这似乎工作得很好。唯一的缺点是有 2 个图像副本,一份位于 EXTRA_OUTPUT 中定义的位置,一份位于默认位置。

What I've done for this is define a location for EXTRA_OUTPUT as a Uri, cache that in a static or member variable, and then in onActivity result use the cached location to retrieve the image. I had the same problem you were describing, and this seems to work fine. The only drawback is having 2 copies of the image, one in the location you defined in EXTRA_OUTPUT, and one in the default location.

七七 2024-12-17 03:52:19

找到答案这是最好的例子,它是对设备的自扰!

AndroidCameraUtils
- 下载项目并从库项目中包含以下是您可以使用的代码片段!

 private void setupCameraIntentHelper() {
    mCameraIntentHelper = new CameraIntentHelper(this, new CameraIntentHelperCallback() {
        @Override
        public void onPhotoUriFound(Date dateCameraIntentStarted, Uri photoUri, int rotateXDegrees) {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_found) + photoUri.toString());

            Bitmap photo = BitmapHelper.readBitmap(CameraIntentActivity.this, photoUri);
            if (photo != null) {
                photo = BitmapHelper.shrinkBitmap(photo, 300, rotateXDegrees);
                ImageView imageView = (ImageView) findViewById(de.ecotastic.android.camerautil.sample.R.id.activity_camera_intent_image_view);
                imageView.setImageBitmap(photo);
            }
        }

        @Override
        public void deletePhotoWithUri(Uri photoUri) {
            BitmapHelper.deleteImageWithUriIfExists(photoUri, CameraIntentActivity.this);
        }

        @Override
        public void onSdCardNotMounted() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sd_card_not_mounted), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCanceled() {
            Toast.makeText(getApplicationContext(), getString(R.string.warning_camera_intent_canceled), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCouldNotTakePhoto() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_could_not_take_photo), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onPhotoUriNotFound() {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_not_found));
        }

        @Override
        public void logException(Exception e) {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sth_went_wrong), Toast.LENGTH_LONG).show();
            Log.d(getClass().getName(), e.getMessage());
        }
    });
}

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    mCameraIntentHelper.onSaveInstanceState(savedInstanceState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mCameraIntentHelper.onRestoreInstanceState(savedInstanceState);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    mCameraIntentHelper.onActivityResult(requestCode, resultCode, intent);
}
}
  • 将以下行添加到您的活动的清单文件android:configChanges="keyboardHidden|orientation|screenSize"

注意:-我尝试了许多相机实用程序的示例,当然还有其他方法处理它,但对于初学者和不太熟悉核心概念的人来说,这个项目会更舒服。谢谢!

Found answer here is the best example which is it self bothering about the device!

AndroidCameraUtils
- Download the project and from library project by including it below is the code snippet you can use !

 private void setupCameraIntentHelper() {
    mCameraIntentHelper = new CameraIntentHelper(this, new CameraIntentHelperCallback() {
        @Override
        public void onPhotoUriFound(Date dateCameraIntentStarted, Uri photoUri, int rotateXDegrees) {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_found) + photoUri.toString());

            Bitmap photo = BitmapHelper.readBitmap(CameraIntentActivity.this, photoUri);
            if (photo != null) {
                photo = BitmapHelper.shrinkBitmap(photo, 300, rotateXDegrees);
                ImageView imageView = (ImageView) findViewById(de.ecotastic.android.camerautil.sample.R.id.activity_camera_intent_image_view);
                imageView.setImageBitmap(photo);
            }
        }

        @Override
        public void deletePhotoWithUri(Uri photoUri) {
            BitmapHelper.deleteImageWithUriIfExists(photoUri, CameraIntentActivity.this);
        }

        @Override
        public void onSdCardNotMounted() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sd_card_not_mounted), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCanceled() {
            Toast.makeText(getApplicationContext(), getString(R.string.warning_camera_intent_canceled), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCouldNotTakePhoto() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_could_not_take_photo), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onPhotoUriNotFound() {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_not_found));
        }

        @Override
        public void logException(Exception e) {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sth_went_wrong), Toast.LENGTH_LONG).show();
            Log.d(getClass().getName(), e.getMessage());
        }
    });
}

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    mCameraIntentHelper.onSaveInstanceState(savedInstanceState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mCameraIntentHelper.onRestoreInstanceState(savedInstanceState);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    mCameraIntentHelper.onActivityResult(requestCode, resultCode, intent);
}
}
  • Add below lined to manifest file of your activityandroid:configChanges="keyboardHidden|orientation|screenSize"

NOTE:- I tried many examples for camera utils and ofcourse there are another ways to handle it but for beginners and person who are not too much familier with the core concepts would be more comfort with this project. THanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文