如何获取应用程序包名或UID这是试图绑定从onBind功能,我的服务? [英] How to get application package name or UID which is trying to bind my service from onBind function?

查看:1764
本文介绍了如何获取应用程序包名或UID这是试图绑定从onBind功能,我的服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序服务,我可以达到不同的应用程序此服务。 当应用程序试图结合这项服务,我想知道哪些应用程序正在试图绑定我​​的服务onBind功能, 但我不能让包名称中onBind功能此应用程序或UID。

I have a service in an application, and I can reach this service from different applications. And when applications are tried to bind this service I want to know which application is trying to bind my service in onBind function, but I can't get the package name or UID of this application in onBind function.

是否有可能获得应用程序的名称或UID这是试图绑定我​​的服务onBind功能?

Is it possible to get the application name or UID which is trying to bind my service in onBind function?

推荐答案

您可以使用以下方法来确定调用应用程序。

You can use the following to determine the calling application.

 String callingApp = context.getPackageManager().getNameForUid(Binder.getCallingUid());

要注意的JavaDoc getCallingUid() 它说:

It's important to note the JavaDoc for getCallingUid() which says:

返回分配给送你正在处理当前事务的过程中,Linux的UID。此流体可以与更高级别的系统服务,以确定其身份,并检查权限。如果当前线程不是当前执行传入的事务,那么它自己的uid返回。

Return the Linux uid assigned to the process that sent you the current transaction that is being processed. This uid can be used with higher-level system services to determine its identity and check permissions. If the current thread is not currently executing an incoming transaction, then its own uid is returned.

这篇关于如何获取应用程序包名或UID这是试图绑定从onBind功能,我的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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