44import android .app .AlertDialog ;
55import android .content .Intent ;
66import android .content .Intent .ShortcutIconResource ;
7+ import android .graphics .Bitmap ;
8+ import android .graphics .BitmapFactory ;
79import android .net .Uri ;
810import android .os .Build ;
911import android .os .Bundle ;
@@ -75,6 +77,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
7577 }
7678
7779 public static native String queryGameName (String path );
80+ public static native byte [] queryGameIcon (String path );
7881
7982 // Create shortcut as response for ACTION_CREATE_SHORTCUT intent.
8083 private void respondToShortcutRequest (Uri uri ) {
@@ -99,13 +102,13 @@ private void respondToShortcutRequest(Uri uri) {
99102 if (path .startsWith ("content://" )) {
100103 String [] segments = path .split ("/" );
101104 try {
102- pathStr = java .net .URLDecoder .decode (segments [segments .length - 1 ], StandardCharsets . UTF_8 . name () );
105+ pathStr = java .net .URLDecoder .decode (segments [segments .length - 1 ], "UTF-8" );
103106 } catch (Exception e ) {
104107 Log .i (TAG , "Exception getting name: " + e );
105108 }
106109 } else if (path .startsWith ("file:///" )) {
107110 try {
108- pathStr = java .net .URLDecoder .decode (path .substring (7 ), StandardCharsets . UTF_8 . name () );
111+ pathStr = java .net .URLDecoder .decode (path .substring (7 ), "UTF-8" );
109112 } catch (Exception e ) {
110113 Log .i (TAG , "Exception getting name: " + e );
111114 }
@@ -116,16 +119,19 @@ private void respondToShortcutRequest(Uri uri) {
116119 String [] pathSegments = pathStr .split ("/" );
117120 name = pathSegments [pathSegments .length - 1 ];
118121
119- /*
120- // No longer working for various reasons.
121-
122122 PpssppActivity .CheckABIAndLoadLibrary ();
123- String name = queryGameName(path);
124- if (name.equals("")) {
123+ String gameName = queryGameName (path );
124+ byte [] iconData = null ;
125+ if (gameName .equals ("" )) {
125126 Log .i (TAG , "Failed to retrieve game name - ignoring." );
126- showBadGameMessage();
127- return;
128- }*/
127+ // This probably happened because PPSSPP isn't running so the GameInfoCache isn't working.
128+ // Let's just continue with our fallback name until we can fix that.
129+ // showBadGameMessage();
130+ // return;
131+ } else {
132+ name = gameName ;
133+ iconData = queryGameIcon (path );
134+ }
129135
130136 Log .i (TAG , "Game name: " + name + " : Creating shortcut to " + uri .toString ());
131137
@@ -134,9 +140,23 @@ private void respondToShortcutRequest(Uri uri) {
134140 Intent responseIntent = new Intent ();
135141 responseIntent .putExtra (Intent .EXTRA_SHORTCUT_INTENT , shortcutIntent );
136142 responseIntent .putExtra (Intent .EXTRA_SHORTCUT_NAME , name );
137- ShortcutIconResource iconResource = ShortcutIconResource .fromContext (this , R .drawable .ic_launcher );
138- responseIntent .putExtra (Intent .EXTRA_SHORTCUT_ICON_RESOURCE , iconResource );
139143
144+ boolean setIcon = false ;
145+ if (iconData != null ) {
146+ // Try to create a PNG from the iconData.
147+ Bitmap bmp = BitmapFactory .decodeByteArray (iconData , 0 , iconData .length );
148+ if (bmp != null ) {
149+ // Scale it to a square.
150+ Bitmap scaledBitmap = Bitmap .createScaledBitmap (bmp , 144 , 144 , true );
151+ responseIntent .putExtra (Intent .EXTRA_SHORTCUT_ICON , scaledBitmap );
152+ }
153+ setIcon = true ;
154+ }
155+ if (!setIcon ) {
156+ // Fall back to the PPSSPP icon.
157+ ShortcutIconResource iconResource = ShortcutIconResource .fromContext (this , R .drawable .ic_launcher );
158+ responseIntent .putExtra (Intent .EXTRA_SHORTCUT_ICON_RESOURCE , iconResource );
159+ }
140160 setResult (RESULT_OK , responseIntent );
141161
142162 // Must call finish for result to be returned immediately
0 commit comments