Saturday, December 2, 2017

Ambient Lock Screen Music is a Root App that Shows any Music on the Pixel 2’s Ambient Display

Google's latest Pixel 2 and Pixel 2 XL flagships have an awesome new feature called "Now Playing." Using a combination of software, hardware, and machine learning, the Pixel 2 uses an offline database to identify tens of thousands of songs playing in the background. It then displays those songs on your device's lock screen, always on display, or as an ongoing notification. The feature sounds gimmicky on paper, but after using it myself I found that it works really well. That being said, this kind of feature isn't everyone's cup of tea, so XDA Recognized Contributor Quinny899 came up with an app called Ambient Lock Screen Music which allows you to display the name and artist of any currently playing song on your device where the Now Playing text would normally appear.

As you can see in the video above, the developer enables the app and then starts playing a song from Google Play Music. When they show the lock screen, you can see the currently playing song at the bottom where you would normally see the Now Playing feature insert text when it recognizes a song.

The application only works on the Pixel 2/2 XL as it sends an intent whose corresponding intent receiver is only available in the SystemUIGoogle app present on the Pixel 2. Furthermore, the application requires root access in order to function. You can download the application from XDA Labs at the link below.

Ambient Lock Screen Music (Free, XDA Labs) →

It is not only free, but it's also totally ad-free as well. It supports displaying song titles/artists from almost any music app such as Google Play Music, Spotify, YouTube Red, and more. You can also blacklist apps from showing text on the ambient display. Finally, the app even allows you to double tap on the text shown on the ambient display to launch the music app.


How Ambient Lock Screen Music Works

The Intent

As mentioned previously, this application works by sending an intent to the SystemUIGoogle application. In Quinny899's app, this is the code responsible for sending the intent:

  Intent intent = new Intent("com.google.android.ambientindication.action.AMBIENT_INDICATION_SHOW").putExtra("com.google.android.ambientindication.extra.VERSION", 1).putExtra("com.google.android.ambientindication.extra.TEXT", broadcastString).putExtra("com.google.android.ambientindication.extra.TTL_MILLIS", time);  if(clickIntent != null)intent.putExtra("com.google.android.ambientindication.extra.OPEN_INTENT", clickIntent);  else if(packageName != null) intent.putExtra("com.google.android.ambientindication.extra.OPEN_INTENT", PendingIntent.getActivity(context, 1, context.getPackageManager().getLaunchIntentForPackage(packageName), 0));  intent.setPackage(pName);  context.sendBroadcast(intent, "com.google.android.ambientindication.permission.AMBIENT_INDICATION");  

Let's break this down some. The action in this intent is "com.google.android.ambientindication.action.AMBIENT_INDICATION_SHOW" and it has a few intent extras that can be send with it.

The first extra is "com.google.android.ambientindication.extra.VERSION" which currently just takes an integer value of 1. The next extra is "com.google.android.ambientindication.extra.TEXT" which is where we set the string that we want displayed on the ambient display lock screen. The third extra is "com.google.android.ambientindication.extra.OPEN_INTENT" which accepts a PendingIntent that opens on a double tap of the text. Quinny899 set the PendingIntent to open up whatever application is playing music or a picker for android.intent.action.MUSIC_PLAYER.

Finally, in order to send this intent, the calling app must have the permission "com.google.android.ambientindication.permission.AMBIENT_INDICATION." This permission is defined as signature|privileged so that is why this app requires root access.

If you want to test this on your own, you can open up a rooted terminal or ADB shell session and enter the following command:

  am broadcast -a com.google.android.ambientindication.action.AMBIENT_INDICATION_SHOW --ei com.google.android.ambientindication.extra.VERSION 1 --es com.google.android.ambientindication.extra.TEXT "hello world"  

This will display the text "hello world" on the ambient display. It won't allow you to double click

Displaying the Song

The app has two methods for capturing what song is being played. The first is through MediaController, which requires the app to be bound as a notification listener (though it doesn't actually mean that the app is intercepting notifications to read the currently playing song). The second is through broadcast receivers which doesn't require a notification listener (and thus consumes less memory) but is less compatible as some music apps do not send a broadcast intent that this app is set up for.



from xda-developers http://ift.tt/2Arqrqh
via IFTTT

No comments:

Post a Comment