This code is unnecessary:
//get package name of current running application.
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
packageName = mActivityManager.getRunningAppProcesses().get(1).processName;
Try this:
grdPhoto.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//get package name of current running application.
Log.e("Package name:=========== ", "Package name " + getApplicationContext().getPackageName());
}
});
If that doesn't work, you know there's a problem with your ontemclicklistener, so try this in your oncreate method or as a log to show proof that getApplicationContext().getPackageName()
will get the correct application package name.
Toast.makeText(this, getApplicationContext().getPackageName(),Toast.LENGTH_SHORT).show();