【FAQ】【JAVA UI】HarmonyOS 如何获取uid和pid

 【问题描述】

鸿蒙中怎么样可以获取Uid和Pid

 

【解决方案】

 try {
            BundleInfo bundleInfo= getContext().getBundleManager().getBundleInfo(getBundleName(),IBundleManager.GET_BUNDLE_DEFAULT);
            int uid=bundleInfo.uid;
            System.err.println("#######uid====>>"+uid);
           int pid= getContext().getProcessInfo().getPid();
           System.err.println("#######pid====>>"+pid);
        }catch (Exception e){
            e.printStackTrace();
        }

 

【运行效果】

cke_1449.png

欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh

posted @ 2022-08-27 10:12  华为开发者论坛  阅读(290)  评论(0)    收藏  举报