可选权限,以便应用程序可以在所有设备上显示并在某些设备上启用可选功能?

发布于 2025-01-05 22:54:43 字数 819 浏览 1 评论 0原文

Android 中的许多功能都需要在清单中设置使用权限。然后,这些值决定哪些设备将在市场上看到它们。但是,如果该功能是可选的……如果可以使其在许多设备上运行,但只需要少数设备上的许可,该怎么办?

举个例子:假设一个应用程序具有多种功能和大量内容,并且它提供了一个呼叫公司的按钮。这是一个非常方便的功能,而不是写下号码或将其复制粘贴到手机应用程序中。然而,这不是必需的。

如果使用该功能并将电话权限添加到应用程序中,那么这对手机来说一切都很好,但没有平板电脑会在市场中看到该应用程序。

这个问题的一般解决方案是什么?

可以使用不同的权限创建多个应用程序,但这种方法存在很多问题(额外的开发时间、难以保持维护一致、评论和评级分散在不同的应用程序中,以及是否存在多种不同类型的可选权限而不是不同的权限)。每种组合可能都需要应用程序)。

该应用程序可以以编程方式检查该功能是否可用,并根据设备启用或禁用它。问题是,如果应用程序没有权限,那么当它尝试使用该功能时就会崩溃——如果它确实有权限,某些设备将无法在应用程序中找到该应用程序。市场。

在某些情况下,可以完全删除应用程序中的非必要功能以避免该问题。这也不是一个很好的解决方案,因为这些功能在支持它的设备上“很高兴拥有”。

是的,我知道 是否可以拥有“可选”权限in Android? 是一个类似的问题。我希望获得更新的信息和人们发现的其他解决方法(如果有的话)......这个问题的解决方案是什么?除了我上面列出的方法之外,还有其他方法吗?

Many features in Android require a uses-permission to be set in the manifest. These values then determine what devices will see them in the Market. However, what should be done if the feature is optional... if it could be made to run on many devices, but would require the permission only on a few?

An example: let's say an app with multiple features and a good amount of content--and it provides a button to call the company. That's a nice convenient feature, as opposed to writing down the number or copying and pasting it into the phone app. It's not essential, however.

If that feature is used and the telephony permission is added to the app, then that's all well and good for phones--but no tablet would see the app in the Market.

What is a general solution for this problem?

Multiple apps could be made with different permissions, but there's a world of problems with that approach (extra development time, difficulty of keeping maintenance consistent, reviews and ratings split across different apps, and if there are several different types of optional permissions than a different app may be needed for each combination).

The app could programmatically check if the feature is available and enable it or disable it depending on the device. The problem with that is that if the app doesn't have the permission, then it will crash if it tries to use that feature--and if it does have the permission, some devices won't be able to find the app in the Market.

In certain cases, it may be possible to cut out nonessential features from the app entirely to avoid the issue. That's not a great solution either, since those features WOULD be "nice to have" on devices that support it.

Yes, I am aware Is it possible to have "optional" permissions in Android? is a similar question. I'm hoping for newer information and for other workarounds people have found, if any... what is the solution to this issue? Does anyone have other approaches besides the ones I've listed above?

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

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

发布评论

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

评论(1

臻嫒无言 2025-01-12 22:54:43

这个问题的一般解决方案是什么?

对于该特定问题,请将 添加到您的清单中,以指示 功能是可选的。然后,您可以使用 PackageManagerhasSystemFeature() 来确定设备在运行时是否具有非必需功能。

What is a general solution for this problem?

For that specific problem, add <uses-feature android:name="android.hardware.telephony" android:required="false"/> to your manifest, to indicate that this feature is optional. You can then use PackageManager and hasSystemFeature() to determine if a device has the non-required feature at runtime.

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