-1

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;


               }
    });
Mohd Sakib Syed
  • 1,679
  • 1
  • 25
  • 42
  • You should post some example code ([Minimal, Complete, Verifiable Example](https://stackoverflow.com/help/mcve) or a [Short, Self-Contained, Correct Example](http://sscce.org/)). Include what you've already tried and where exactly you're stuck. See more info at [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) Thanks! – Will Dec 29 '15 at 07:21
  • I'm voting to close this question as off-topic because it's a duplicate. – Mogsdad Dec 31 '15 at 20:14

1 Answers1

0
 packageInfo=mActivity.getPackageManager().getPackageInfo(mActivity.getPack
    ageName(), PackageManager.GET_ACTIVITIES);
  • Hi Chandrakant, Thanks for reply. Actuall i want to create custom keyboard to share data to any application so i need package name of that application in which my custom keyboard is open. Your code returns the my custom keyboard package name but i want to package name of that application in which my keyboard is open. – Mohd Sakib Syed Dec 29 '15 at 10:45