6

对不起,我的英语不好。

我的应用程序中有多个Activity,我需要集中运行时应用程序权限。

我需要使用BaseActivity吗?

Activity如果是,请建议我在应用程序中有很多情况下如何处理它。

如果没有,请建议更好的方法来处理它。

我想减少代码冗余。没有兴趣一次又一次地编写相同的代码Activity

我也在寻找用户拒绝许可的负面情况,我必须表现出理性而不是一直要求允许许可。并基于此我必须提供消息或者我必须更新 UI

4

2 回答 2

-1

Run time permission were introduced to have control over the dangerous resources

So ideally you must be checking for the permission every time you use a resource. This code must not be eliminated.

Then when it comes to request a permission, it is a single line code. I don't think you must be having a trouble with this.

Now comes the tricky part. Handling the permissions that are given. You can definitely have a base class (not recommended) but ideally different permission is used for different purpose.

For example location permission:
In same Activity say Location.java, i might need location permission for getting the address of the person using LatLon values, and in the same activity I am using location permission for live tracking the user.

Now to handle different implementations for same permission, you must have unique permissions codes based on the purpose, but not based on the resource you are accessing permission for. Handling all these things in a base class can be tricky. So ideally you must handle permission in the activity where it belongs. It will keep your code safe and prevent any mix ups with other codes.

Always advisable to read the official docs.

There might be cases where you might get confused with redundancy of the codes and multiple implementations. For that, Android is handling most of the code in its end, as a programmer, least expected is to check for permissions and perform appropriate operations wherever dangerous resources are used.

于 2016-10-03T11:01:42.950 回答
-2

如果您有 10 个活动并且所有活动都需要位置权限。那么我想这对您的应用程序来说是非常重要的权限。

对于关键权限,如果用户不允许,您可以关闭您的应用程序,因此在第一个活动本身上执行此操作。就像 facebook 为各种许可所做的那样。这对用户来说可能是不好的体验,但它是您的应用程序的必要权限。

如果用户不允许,只需在第一个活动中编写一次并停止应用程序。许多旗舰应用程序都是这样做的。

于 2016-10-03T11:14:34.033 回答