拦截Android中 [英] Interceptor in Android

查看:107
本文介绍了拦截Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,这需要每次检查认证令牌执行操作来调用Web服务,所以我只好包括在所有活动检查code片段。我想问一个拦截器是否存在于Android平台,如果是,请分享给拦截器应用到我的code中的最佳做法?谢谢你。

I have an Android app, which require to check authentication token every time perform action to call a web service, therefore I had to included the checking code snippet in all activities. I would like to ask whether an interceptor exist in Android platform, if yes, please share the best practice to apply the interceptor to my code? Thanks.

推荐答案

建议不要使用运行时反射为Android,所以你不应该使用它提供运行时截获您的HTTP请求任何库。你可以写一个简单的HTTP请求的工具方法和途径,通过这种方法你所有的HTTP请求。​​

Using run time reflection is not recommended for android, so you should not use any library which provides run time intercepting your HTTP request. You can write a simple HTTP request utility method and route all your HTTP requests through this method.

 public static void makePostRequest(String url, Object body, Context context, AsyncHttpResponseHandler handler) { // here you can add your authentication token to header}

这篇关于拦截Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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