Skip to content

Commit 27aaa27

Browse files
fix: issues
1 parent df511e4 commit 27aaa27

File tree

1 file changed

+39
-10
lines changed
  • src/plugins/system/android/com/foxdebug/system

1 file changed

+39
-10
lines changed

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@
101101
import android.graphics.Canvas;
102102
import android.util.TypedValue;
103103

104+
import android.provider.MediaStore;
105+
import android.graphics.Bitmap;
106+
import android.os.Build;
107+
import android.graphics.ImageDecoder;
108+
104109

105110

106111
public class System extends CordovaPlugin {
@@ -1095,31 +1100,55 @@ private void pinFileShortcut(JSONObject shortcutJson, CallbackContext callback)
10951100
}
10961101

10971102
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
1098-
callback.error("Not supported");
1103+
callback.error("Pin shortcut not supported on this launcher");
10991104
return;
11001105
}
11011106

11021107
try {
11031108
Uri dataUri = Uri.parse(uriString);
1104-
11051109
String packageName = context.getPackageName();
1106-
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
1110+
PackageManager pm = context.getPackageManager();
1111+
1112+
Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
1113+
if (launchIntent == null) {
1114+
callback.error("Launch intent not found for package: " + packageName);
1115+
return;
1116+
}
1117+
11071118
ComponentName componentName = launchIntent.getComponent();
1119+
if (componentName == null) {
1120+
callback.error("ComponentName is null");
1121+
return;
1122+
}
11081123

11091124
Intent intent = new Intent(Intent.ACTION_VIEW);
11101125
intent.setComponent(componentName);
1111-
11121126
intent.setData(dataUri);
11131127
intent.putExtra("acodeFileUri", uriString);
11141128

11151129
IconCompat icon;
1130+
11161131
if (iconSrc != null && !iconSrc.isEmpty()) {
1117-
ImageDecoder.Source imgSrc = ImageDecoder.createSource(
1118-
context.getContentResolver(),
1119-
Uri.parse(iconSrc)
1120-
);
1121-
Bitmap bitmap = ImageDecoder.decodeBitmap(imgSrc);
1122-
icon = IconCompat.createWithBitmap(bitmap);
1132+
try {
1133+
Uri iconUri = Uri.parse(iconSrc);
1134+
Bitmap bitmap;
1135+
1136+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
1137+
ImageDecoder.Source imgSrc =
1138+
ImageDecoder.createSource(context.getContentResolver(), iconUri);
1139+
bitmap = ImageDecoder.decodeBitmap(imgSrc);
1140+
} else {
1141+
bitmap = MediaStore.Images.Media.getBitmap(
1142+
context.getContentResolver(),
1143+
iconUri
1144+
);
1145+
}
1146+
1147+
icon = IconCompat.createWithBitmap(bitmap);
1148+
1149+
} catch (Exception e) {
1150+
icon = getFileShortcutIcon(label);
1151+
}
11231152
} else {
11241153
icon = getFileShortcutIcon(label);
11251154
}

0 commit comments

Comments
 (0)