【问题标题】:How to retrieve the image from camera without using camera app (via a service)如何在不使用相机应用程序的情况下从相机中检索图像(通过服务)
【发布时间】:2012-09-08 13:11:14
【问题描述】:

我需要创建一个服务应用程序,如果从内置相机应用程序中获取任何新图像,该服务应用程序始终会从其中查找和检索图像文件。

1)如果新图像是从内置相机应用程序中拍摄的,我的服务需要观看和拍摄图像

如何获取我的服务中的图片路径或图片数据。

【问题讨论】:

  • 我尽量按照我的理解编辑您的问题;但你需要澄清你想要发生的事情。尝试使用您希望用户执行的一系列步骤来更新您的问题。例如 1. 打开我的应用程序 2. 单击相机按钮 2. 我的应用程序显示相机视图 3. 用户使用我的应用程序捕获图像。

标签: android android-intent android-camera


【解决方案1】:

清单代码:

 <receiver android:name=".pictureReceiver" >
        <intent-filter android:priority="10000" >
           <action android:name="com.android.camera.NEW_PICTURE"/>
      <data android:mimeType="image/*"/>
        </intent-filter>
</receiver>

接收代码:

@Override
    public void onReceive(Context arg0, Intent arg1) {
           String selectedImageUri = arg1.getData().getPath();
           Log.d("TAG", "Received new photo:::"+selectedImageUri );
               Log.d("TAG","file Path"+getRealPathFromURI(arg1.getData(),arg0));
    }
 public String getRealPathFromURI(Uri contentUri,Context context)
        {
            try
            {
                String[] proj = {MediaStore.Images.Media.DATA};

                Cursor cursor =  context.getContentResolver().query(contentUri, proj, null, null, null);
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                return cursor.getString(column_index);
            }
            catch (Exception e)
            {
                return contentUri.getPath();
            }
        }

【讨论】:

【解决方案2】:

仅供参考,建议收听自 ICS API 级别 14 起的官方广播:http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_PICTURE。所以过滤“android.hardware.action.NEW_PICTURE”,并且仅当您还需要支持 pre-ICS 时才使用“com.android.camera.NEW_PICTURE”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    相关资源
    最近更新 更多