How to get application package name or UID which is trying to bind my service from onBind function?

前端 未结 6 1925
说谎
说谎 2020-12-03 03:17

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 appli

6条回答
  •  隐瞒了意图╮
    2020-12-03 03:52

    You can use the following to determine the calling application.

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

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

    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.

提交回复
热议问题