Android 屏幕有视频时调用邮件问题

发布于 2024-11-01 10:12:02 字数 1705 浏览 4 评论 0原文

我有一个活动,其中有一个视频视图和一个共享按钮。触摸共享按钮后,它会调用邮件客户端。这是我的代码:

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phrasevideo);


        //extraDataHelper.getPhraseDetails(phraseId);
        btnshare = (ImageView) findViewById(R.id.btnshare);




        videoView = (VideoView) findViewById(R.id.VideoView);

        File f=new File(Environment.getExternalStorageDirectory(), "extras/hello.mp4");
        Uri video = Uri.parse(f.getAbsolutePath());            

        videoView.setVideoURI(video);
    btnshare.setVisibility(View.VISIBLE);
            }});
        videoView.start();



        btnshare.setOnTouchListener(new OnTouchListener(){

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub

                final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.setType("text/html"); 
                emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{""}); 
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Language Hostess"); 
                String emailText = "<html><body><p>Hi friends</p></body></html>";
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(emailText));
                startActivityForResult(Intent.createChooser(emailIntent, "Email:"), 1);
                return false;
            }});

    }

一切正常。但是,当我在发送或丢弃邮件后返回应用程序时,视频视图只是黑色。在这里我想提一下,共享按钮仅在视频未播放时才会出现。为什么会发生这种情况?问题的解决办法是什么?

I have a activity which has a VideoView and a button for share. On touch of share button, it invokes the mail client. Here is my code:

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phrasevideo);


        //extraDataHelper.getPhraseDetails(phraseId);
        btnshare = (ImageView) findViewById(R.id.btnshare);




        videoView = (VideoView) findViewById(R.id.VideoView);

        File f=new File(Environment.getExternalStorageDirectory(), "extras/hello.mp4");
        Uri video = Uri.parse(f.getAbsolutePath());            

        videoView.setVideoURI(video);
    btnshare.setVisibility(View.VISIBLE);
            }});
        videoView.start();



        btnshare.setOnTouchListener(new OnTouchListener(){

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub

                final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.setType("text/html"); 
                emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{""}); 
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Language Hostess"); 
                String emailText = "<html><body><p>Hi friends</p></body></html>";
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(emailText));
                startActivityForResult(Intent.createChooser(emailIntent, "Email:"), 1);
                return false;
            }});

    }

Everything is working fine. But when I am coming back to the app after sending or discarding the mail, the videoView is just black. Here I like to mention that the share button appears only when the video is not playing. Why it is happening? What is the solution of the problem?

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

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

发布评论

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

评论(1

如歌彻婉言 2024-11-08 10:12:02

首先,您需要在 onTouch 方法末尾返回 true 以指示您已处理该事件。

至于为什么只有在视频未播放时才会出现共享按钮,这是因为您没有在视图(保存视频的视图)中为其分配空间。您需要将其添加到上下文菜单或选项菜单中,以供用户选择。

至于为什么屏幕是黑色的,可能与您在“共享”活动之后没有处理返回到您的活动有关。请务必描述一个 onReturn 方法。

First off, you need to return true at the end of your onTouch method to indicate that you have handled the event.

As to why the share button appears only when the video is not playing, it's because you have not apportioned space for it in your view (the view that holds the video). You will need to add it to a context menu, or option menu, for the user to select.

As to why the screen is black, it probably has something to do with you not handling the return to your activity after the "sharing" activity. Be sure to have an onReturn method delineated.

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