-3

Can somebody explain me why when I use this code I do not get the full package name?

For example, instead of getting this: com.android.phone.EmergencyDialer.DIAL

I get only com.android.phone.

How can I fix this and get full package name?

final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++)
{
    Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.getPackageName()+ "\t\t ID: "+recentTasks.get(i).id+"");
}

Thank you.

jyanks
  • 2,356
  • 1
  • 19
  • 36
S.Drumble4
  • 139
  • 8
  • Take a look at this http://stackoverflow.com/questions/28066231/how-to-gettopactivity-name-or-get-current-running-application-package-name-in-lo – Deshan Apr 07 '16 at 14:45
  • 2
    `com.android.phone` is the full package name for that task. `com.android.phone.EmergencyDialer.DIAL` is not a package name - what makes you think you should be getting that? – laalto Apr 07 '16 at 14:53
  • @laalto So, can I somehow get `com.android.phone.EmergencyDialer.DIAL`? – S.Drumble4 Apr 07 '16 at 14:58
  • What do you need it for? If all you want is that string, hardcode it. – laalto Apr 07 '16 at 15:18
  • @laalto No, I want to know is emergency dialer in the foreground or not – S.Drumble4 Apr 07 '16 at 15:32

1 Answers1

0

It's not going to be possible to get com.android.phone.EmergencyDialer.DIAL from the ActivityManager, since com.android.phone is the actual package name, com.android.phone.EmergencyDialer.DIAL is a field for the intent action on the EmergencyDialer class.

See: https://android.googlesource.com/platform/packages/services/Telephony/+/idea133/src/com/android/phone/EmergencyDialer.java

You would need to give a better example of what you're trying to accomplish here, but again, getting the DIAL variable is just not going to be possible from the ActivityManager class, as com.android.phone.EmergencyDialer.DIAL is not and will never be a valid running task.

jyanks
  • 2,356
  • 1
  • 19
  • 36
  • I want to know is emergency dialer in the foreground or not – S.Drumble4 Apr 07 '16 at 15:38
  • So the problem is that emergency dialer is really just a screen within the com.android.phone application. There's no straightforward way to know if they have left the emergency dialer, and probably not what you want anyway - technically speaking, making a phone call from the emergency dialer would technically be leaving the emergency dialer. That being said, you COULD detect if the user has pushed the phone app from the foreground by doing some kind of AlarmManager polling on the current running package. That's probably as close as you'll get to detecting emergency dialer. – jyanks Apr 07 '16 at 17:05
  • Well, as I understand emergency dialer and calling have different packages . So, I will be able to detect opening and closing of emergency dialer by comparing package of app that is on the top of all at the moment with package of emergency dialer but if user will just call to anyone my app will get the package of calling and will be closed cause my code do this, right? – S.Drumble4 Apr 08 '16 at 01:49
  • You are mistaken. The EmergencyDialer.DIAL is simply an intent parameter. Sorry, but currently there is no way to know whether or not the emergency dialer is in the foreground. You can only see whether or not the phone app is running. – jyanks Apr 11 '16 at 03:40