如何在Android中请求成为默认视频播放器的权限?

huangapple go评论78阅读模式
英文:

How to ask for the permission to become Default Video Player in Android?

问题

我正在开发一个视频播放器应用,我希望我的应用能够提示用户授予权限,成为默认的视频播放器处理程序。我知道大致的操作步骤如下:

Intent setVideoAppIntent =
    new Intent(Intent.ACTION_DEFAULT);
setVideoAppIntent.putExtra(Intent.EXTRA_PACKAGE_NAME,
    getPackageName());
startActivityForResult(setVideoAppIntent, your-result-code);

但是我不清楚在Intent中需要设置哪个操作(Action)。是否有人可以帮助我一下?提前谢谢!

英文:

I am developing a video player app and I want my app to Prompt for the permission to be the default Video Player to be the default handler of video play.
I know it has to be something like the default handler:

Intent setSmsAppIntent =
    new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
setSmsAppIntent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
    getPackageName());
startActivityForResult(setSmsAppIntent, your-result-code);`

source: Android Docs

But I don't know the Action I have to give to the Intent as action. Can someone please help me?
Thanks in advance.

答案1

得分: 2

这是翻译后的内容:

无法实现,开发者无法调用意图来更改默认视频播放器,只有用户可以在其设备上执行此操作。这仅适用于“短信服务”。

然而,对于视频播放器,您可以在AndroidManifest.xml中注册视频播放器应用,并使用以下代码调用打开设置以更改默认应用程序的功能:

Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
英文:

It's not possible, developers can't call intent to change default Video player only users can do that on their device. Its only possible for SMS service.

However, for video player you can register app for video player in AndroidManifest.xml and call the function which opens settings to change default apps using the following code:

Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

huangapple
  • 本文由 发表于 2020年9月4日 11:17:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63734305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定