Package name of current running application package name Android 6.0 [duplicate]

☆樱花仙子☆ 提交于 2020-01-11 14:43:06

问题


I am using custom keyboard to share image to any app like Facebook,whatsApp and i want to know the current open application package name on onIteamClickListener of my custom keyboard to share data without chooser dialog. Below is my code

grdPhoto.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


            ActivityManager am = (ActivityManager)MainActivity.this.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningAppProcessInfo> tasks = am.getRunningAppProcesses();
            String packageName = tasks.get(1).processName;


               }
    });

回答1:


 packageInfo=mActivity.getPackageManager().getPackageInfo(mActivity.getPack
    ageName(), PackageManager.GET_ACTIVITIES);


来源:https://stackoverflow.com/questions/34506199/package-name-of-current-running-application-package-name-android-6-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!