2

I am trying to get the package name of the default android clock (stock clock).

This is the intent I use to open the stock clock.

Intent i = new Intent(AlarmClock.ACTION_SHOW_ALARMS);

I have tried

i.getPackage();

But this returns null. Is there a way to get the package name of the default clock in android, in any phone?

Rishabh Bhardwaj
  • 207
  • 5
  • 14
  • Why do you need it? See this answer anyway: http://stackoverflow.com/a/4281243/4059697 – uneven Sep 11 '15 at 12:49
  • I am currently using this but this isnt a robust solution. There are some phones that arent covered in that list. - Even then, there should be a way to get the name of the package being opened from the intent, right? – Rishabh Bhardwaj Sep 11 '15 at 12:52

2 Answers2

4

But this returns null

That is because you have not set the package name in the Intent.

Is there a way to get the package name of the default clock in android, in any phone?

Not really, as there is no concept of a "default clock" in Android.

However, you can use PackageManager and queryIntentActivities() to see what activities will respond to the Intent that you have constructed.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • ^ Still not very helpful. `List infos = getPackageManager().queryIntentActivities(new Intent(AlarmClock.ACTION_SHOW_ALARMS), 0);` Printing resolvepackagename returns null. activityinfo returns something that doesnt help either. – Rishabh Bhardwaj Sep 12 '15 at 14:08
3

Hope this will help you:

final PackageManager packageManager = this.getPackageManager();
Intent intent = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
List<ResolveInfo> packages = packageManager.queryIntentActivities(intent,0);
    for(ResolveInfo res : packages){

        String package_name = res.activityInfo.packageName;
        Log.w("Package Name: ",package_name);

    }