I am using Android 6.0 and open the camera intent by
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
getApplication().startActivity(intent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
}
It will open my camera intent. If I press the movie button, the movie GUI will be shown. I want to distinguish the camera and movie intent. How can I know it by programming because both of them have the name are camera. This is my code to get current process name
String foregroundProcess = null;
UsageStatsManager mUsageStatsManager = (UsageStatsManager) getApplicationContext().getSystemService(Service.USAGE_STATS_SERVICE);
long time = System.currentTimeMillis();
UsageEvents usageEvents = mUsageStatsManager.queryEvents(time - 1000 * 3600, time);
UsageEvents.Event event = new UsageEvents.Event();
while (usageEvents.hasNextEvent()) {
usageEvents.getNextEvent(event);
if(event.getEventType() == UsageEvents.Event.MOVE_TO_FOREGROUND) {
foregroundProcess = event.getPackageName();
}
}
//Convert package name to application name
final PackageManager pm = getApplicationContext().getPackageManager();
ApplicationInfo ai;
try {
ai = pm.getApplicationInfo(foregroundProcess, 0);
} catch (final PackageManager.NameNotFoundException e) {
ai = null;
}
String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");
return applicationName;