2013-09-26 21 views
-1

我正在创建一个应用程序,该应用程序将调用相机意图,并希望为拍摄的图像添加经度和纬度。它会是可行的吗?Android:调用相机意图并设置经度和纬度

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = Uri.fromFile(getOutputPhotoFile());
i.putExtra(MediaStore.EXTRA_OUTPUT,fileUri);

i.putExtra(“latitude”,“11111”);
i.putExtra(“longitude”,“222”);

startActivityForResult(i,CAPTURE_IMAGE_ACTIVITY_REQ);

+0

这是不可能的。经纬度由相机应用程序控制。如果你想设置它们,你可以自己实现相机应用程序,而不是调用系统相机应用程序 – yushulx

回答

1

您正在使用相机应用程序,这不适合您的目的。因为你不能覆盖相机应用上的任何对象。你只能从它得到一个图像。所以你必须创建你的内置相机应用程序,并将其用于你的目的。 我带一个使用内置相机的例子。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<SurfaceView android:id="@+id/CameraView" android:layout_width="fill_parent" 
android:layout_height="fill_parent"></SurfaceView> 
</LinearLayout> 

现在创建活动像这样实现SurfaceHolder.Callback

import android.app.Activity; 
import android.os.Bundle; 
import android.view.SurfaceHolder; 
import android.view.SurfaceView; 
public class SnapShot extends Activity implements SurfaceHolder.Callback { 
    SurfaceView cameraView; 
    SurfaceHolder surfaceHolder; 
    Camera camera; 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     cameraView = (SurfaceView) this.findViewById(R.id.CameraView); 
     surfaceHolder = cameraView.getHolder(); 
     surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
     surfaceHolder.addCallback(this); 
    } 
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 
    } 
    public void surfaceCreated(SurfaceHolder holder) { 
    camera = Camera.open(); 
    try 
    { 
     camera.setPreviewDisplay(holder); 
    } 
     catch (IOException exception) 
    { 
     camera.release(); 
    } 
    camera.startPreview(); 
    } 
    public void surfaceDestroyed(SurfaceHolder holder) { 
    } 
} 
+0

不要忘记在Androidmanifest.xml中为你的项目添加使用权限。 –

0

首先,您必须确保您要启动的系统相机应用程序接受参数latitudelongitude,否则在我看来这是毫无意义的。
你需要建立你自己的定制相机应用程序,这是不难实现这一点。