可选权限,以便应用程序可以在所有设备上显示并在某些设备上启用可选功能? [英] Optional permissions so an app can show on all devices and enable optional features on some?

查看:22
本文介绍了可选权限,以便应用程序可以在所有设备上显示并在某些设备上启用可选功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

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

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?

推荐答案

这个问题的通用解决方案是什么?

What is a general solution for this problem?

对于该特定问题,将 <uses-feature android:name="android.hardware.telephony" android:required="false"/> 添加到您的清单,以表明 这个功能是可选的.然后,您可以使用 PackageManagerhasSystemFeature() 来确定设备在运行时是否具有非必需功能.

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.

这篇关于可选权限,以便应用程序可以在所有设备上显示并在某些设备上启用可选功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆