【问题标题】:How to prevent "complete action using" dialogbox in android application如何防止android应用程序中的“完成操作使用”对话框
【发布时间】:2011-08-03 12:07:57
【问题描述】:

我正在使用代码在 Android 应用程序中播放 YouTube 视频
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(youtube_video_url)));
当我尝试在设备上播放视频时,它会弹出一个对话框“完成操作使用”,其中包含 Internet 和 YouTube 选项。我怎样才能防止这个弹出并直接在 YouTube 播放器中打开 YouTube 视频。此外,有没有办法像 Engadget 那样直接在视频播放器中播放 YouTube 视频(通过避免 YouTube 播放器)。

【问题讨论】:

  • 你为什么想要那个?如果用户没有那个特定的播放器,或者想要另一个播放器怎么办?选择应该是用户的。如果你想默认打开 youtube,de 用户实际上可以为这样的意图添加该设置(默认应用程序设置)。它正在从用户手中夺走默认选项,这绝不是一件好事。
  • 在我的情况下,我必须使用 YouTube 作为默认设置,我该如何进行该设置,因为在 android 设备上运行的 YouTube 应用程序之一没有显示弹出窗口,但我的应用程序显示了。我需要避免“使用”弹出窗口的“完整操作”
  • 我的论点是你不需要避免它。如果用户想避免看电影,请通过正确设置手机(默认应用程序设置)让他们这样做。如果用户想在浏览器中看 youtube 电影,让他们看。如果他们不这样做,他们可以选择不去吗?你没有提供任何论据为什么你应该想要这个?
  • 默认应用设置有效,但我想避免手动设置默认选项,因为我的应用只有 YouTube 视频,所以应该直接在 YouTube 播放器中播放。这也是客户要求直接在 YouTube 以外的全屏视频播放器中播放 YouTube 视频,或者如果必须在 YouTube 中播放,至少要避免该弹出窗口。
  • 避免“完整操作使用”的另一个原因是用于信息亭或 COSU 设备(企业拥有的单次使用)。我在尝试让 TextToSpeech 工作而不需要用户做出选择时遇到了这个问题。更重要的是,由于用户可能已经通过发出语音命令启动了 TextToSpeech 操作,因此他们没有看设备。

标签: android popup youtube android-video-player


【解决方案1】:

这是您有兴趣调用的WatchActivity

<activity android:name="WatchActivity" android:screenOrientation="sensor" android:configChanges="keyboardHidden|orientation" android:allowTaskReparenting="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.youtube.com" android:pathPrefix="/watch" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.youtube.com" android:pathPrefix="/v/" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.youtube.com" android:pathPrefix="/e/" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="vnd.youtube" />
    </intent-filter>
</activity>

这不是默认的activity,就是要直接调用它,你得试试下面的代码

String youtubePackage = "com.google.android.youtube";
ArrayList<IntentFilter> intentFilters = new ArrayList<IntentFilter>();
/*
 * Filter to match
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.youtube.com" android:pathPrefix="/watch" />
    </intent-filter>
 */
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_VIEW);
filter.addCategory(Intent.CATEGORY_DEFAULT);
filter.addCategory(Intent.CATEGORY_BROWSABLE);
//filter.addDataScheme("http");
//filter.addDataAuthority("www.youtube.com", null);//port null will allow any port
//filter.addDataPath("/watch", PatternMatcher.PATTERN_PREFIX);
intentFilters.add(filter);
ArrayList<ComponentName> outActivities = new ArrayList<ComponentName>();
getPackageManager().getPreferredActivities(intentFilters, outActivities, youtubePackage);

在最后一次调用之后,outActivities 变量将保存匹配活动(很可能只有一个)。事实上,它不会为我返回任何东西。

要确保 Activitys 与您的 Intent 匹配,您可以查询包

Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.youtube.com/watch?v=EUXnJraKM3k"));         
List<ResolveInfo> matchingActivities = getPackageManager().queryIntentActivities(videoIntent, PackageManager.MATCH_DEFAULT_ONLY);

或者放弃所有冗长的程序,然后继续

Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:<video id>"));
startActivity(videoIntent);

vnd.youtubeWatchActivity 过滤器接受的方案,如您所见。

【讨论】:

  • 当您startActivityForResult 时,您传递一个数字作为第二个参数,这是您自己的活动标识符。忽略最后一行,使用普通的startActivity(videlClient)
  • 以下行应该保持不变还是我应该将其更改为我自己的包和活动? videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.PlayerActivity");因为我尝试了你提到的代码,但它抛出了异常。
  • 我猜异常会告诉您类似have you declared this activity in your AndroidManifest.xml? 的信息,不是吗?这实际上让您了解到您必须在清单中声明 com.google.android.youtube.PlayerActivity 活动,就像您的其他活动一样。
  • 不,行必须是它是什么,com.google.android.youtube 包和PlayerActivity 活动。
  • 我在 AndroidManifest.xml 中指定了以下活动 但它仍然给出了异常:android.content.ActivityNotFoundException:找不到明确的活动类{com.google.android.youtube/com.google.android.youtube.PlayerActivity};您是否在 AndroidManifest.xml 中声明了此活动?这是关于同一问题的一些讨论。 com.google.android.youtube intent not found
猜你喜欢
  • 2011-05-23
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多