问题
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