From 23685d94ec649de027a742ed9da9fe16f87165a4 Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Sat, 28 Nov 2015 02:00:50 +0100 Subject: [PATCH] Add App-recognition support if a MediaPlayer also sends it's packagename in a StringExtra "scrobbling_source" along with "com.android.music.XXX" intents --- .../receiver/BuiltInMusicAppReceiver.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java b/app/src/main/java/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java index 503e2dea..c74c6c77 100644 --- a/app/src/main/java/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java +++ b/app/src/main/java/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java @@ -22,6 +22,7 @@ import android.content.ContentUris; import android.content.Context; +import android.content.pm.PackageManager; import android.database.Cursor; import android.os.Bundle; import android.provider.MediaStore; @@ -95,8 +96,23 @@ protected void parseIntent(Context ctx, String action, Bundle bundle) } MusicAPI getMusicAPI(Context ctx, Bundle bundle) { - CharSequence bundleAppName = bundle.getCharSequence("player"); - CharSequence bundleAppPackage = bundle.getCharSequence("package"); + CharSequence bundleAppName; + CharSequence bundleAppPackage; + + bundleAppPackage = bundle.getCharSequence("scrobbling_source"); + if (bundleAppPackage != null) + { + PackageManager packageManager = ctx.getPackageManager(); + try { + bundleAppName = packageManager.getApplicationLabel(packageManager.getApplicationInfo(bundleAppPackage.toString(), PackageManager.GET_META_DATA)); + } catch (PackageManager.NameNotFoundException e) { + bundleAppName = bundle.getCharSequence("player"); + bundleAppPackage = bundle.getCharSequence("package"); + } + } else { + bundleAppName = bundle.getCharSequence("player"); + bundleAppPackage = bundle.getCharSequence("package"); + } MusicAPI musicAPI; if ((bundleAppName != null) && (bundleAppPackage != null)) {