首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从其他活动返回数据,返回按钮是从启动的活动返回的唯一方法

如何从其他活动返回数据,返回按钮是从启动的活动返回的唯一方法
EN

Stack Overflow用户
提问于 2013-11-01 13:16:08
回答 2查看 168关注 0票数 0

我有一台lg g-slate,它有两个后置摄像头,可以拍摄立体(3D)照片/视频。在我的应用程序中,我正在尝试调用设备上预装的3D录像机应用程序。我成功地启动了应用程序,如下所示:

代码语言:javascript
复制
    Intent i;
    PackageManager manager = getPackageManager();
    try {
        i = manager.getLaunchIntentForPackage("com.lge.stereo.camcorder");
        if (i == null)
            throw new PackageManager.NameNotFoundException();
        i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivityForResult(i, ACTION_TAKE_VIDEO);
    } catch (PackageManager.NameNotFoundException e) {

使用该应用程序录制视频后,除了使用后退按钮外,无法从该应用程序返回。因此,在onActivityResult()中,结果代码是RESULT_CANCELLED,我无法获得从intent返回的任何数据。我想要获取保存视频的文件的Uri,但我不确定如何能够做到这一点,因为使用后退按钮是从应用程序返回的唯一方式。

我之前使用过以下代码来录制2D视频:

代码语言:javascript
复制
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);

录制视频后,会弹出一个对话框,您可以在其中选择"Ok“返回您的应用程序并获取onActivityResult中的文件URI。

有什么方法可以启动3D录像机,这样我就可以得到结果了吗?

如有任何帮助或建议,我们将不胜感激。谢谢

EN

回答 2

Stack Overflow用户

发布于 2013-11-01 13:23:18

打开相机应用程序在您的应用程序中仅在自定义布局上使用。你可以有两个按钮来保存和丢弃视频。当用户按下保存视频时,将其保存在预定义的位置上,您将知道视频的路径,因为您已经自己定义了它,当用户按下取消视频时,放弃该位置并取消视频,或者只是覆盖后退按钮功能。

例如

在onCreate()方法中,获取camera的实例

代码语言:javascript
复制
private Camera myCamera;
// Get Camera for preview
myCamera = getCameraInstance();


private Camera getCameraInstance() {
        // TODO Auto-generated method stub
        Camera c = null;
        try {
            // attempt to get a Camera instance
            c = Camera.open();
        } catch (Exception e) {
            // Camera is not available (in use or does not exist)
        }
        // returns null if camera is unavailable
        return c;
    }

现在为相机创建曲面视图

代码语言:javascript
复制
         private MyCameraSurfaceView myCameraSurfaceView;

        myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera);
        FrameLayout myCameraPreview = (FrameLayout) findViewById(R.id.videoview);
        myCameraPreview.addView(myCameraSurfaceView);

        myButton = (Button) findViewById(R.id.mybutton);
        myButton.setOnClickListener(myButtonOnClickListener);

        flashOff = (RadioButton) findViewById(R.id.flashoff);
        flashTorch = (RadioButton) findViewById(R.id.flashtorch);

然后像这样创建你的布局

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <FrameLayout
            android:id="@+id/videoview"
            android:layout_width="720px"
            android:layout_height="480px" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <Button
                android:id="@+id/mybutton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="REC"
                android:textSize="12dp" />

            <RadioGroup
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <RadioButton
                    android:id="@+id/flashoff"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:text="OFF"
                    android:textSize="8dp" />

                <RadioButton
                    android:id="@+id/flashtorch"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Torch"
                    android:textSize="8dp" />
            </RadioGroup>

            <Button
                android:layout_marginTop="10dp"
                android:id="@+id/btn_next"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="NEXT"
                android:textSize="12dp" />


        </LinearLayout>
    </LinearLayout>

</LinearLayout>
票数 0
EN

Stack Overflow用户

发布于 2013-11-01 15:39:17

我找到了一个合适的解决方案。在调用startActivityForResult之前,我以毫秒为单位获取当前时间,然后以onActivityResult为单位获取当前时间。我知道3D录像机保存视频的目录,所以我遍历目录中的文件并检查每个文件的最后修改时间。如果上次修改的时间介于使用3D记录器应用程序的开始时间和结束时间之间,我就知道这就是录制的视频。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19721218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档