WAI
Status Update
Comments
lb...@gmail.com <lb...@gmail.com> #2
This issue does not reproduce with dev preview 4.
dn...@google.com <dn...@google.com>
dn...@google.com <dn...@google.com> #3
Closing this issue as per comment #2 from reporter.
dn...@google.com <dn...@google.com> #4
As of Android O, legacy shortcuts are deprecated (and not supported in certain cases). Developers need to migrate to using the ShortcutManager (N-MR1) and related APIs. This ShortcutInfo object does not support uri based icons or referring icons from other packages.
The only alternative is to include the resource in the app package or use Bitmap based icons.
The only alternative is to include the resource in the app package or use Bitmap based icons.
lb...@gmail.com <lb...@gmail.com> #5
@4 Then how would you set the image to be of the app you've created the shortcut to? How would it always take the most updated icon of it?
Bitmap solution can't do it, as it's never changing.
Why not support creating shortcuts of other apps, and showing their icons?
The ShortcutInfo cannot be used in the new API (ShortcutManager), which is why I wrote this bug report.
You can't include all resources of all apps on the play store on your app. It's impossible. Apps get updated, added, and removed all the time on the Play Store.
What you are suggesting is not possible.
Suppose I want to create a shortcut to Gmail app using the new API, what would I choose to do? If I choose a bitmap, it will stay this way no matter if the Gmail app gets updated with new icon. Not only that, but on previous API, I didn't even need to decode the bitmap.
Please, always provide alternatives to existing features in case they need to be replaced. It can't be that I had this feature on previous versions, that I had on my app, and now I can't. It wasn't even marked as "for debug purposes" or "not for use on third party apps". This was a 100% legit API. It should have a good alternative API.
Bitmap solution can't do it, as it's never changing.
Why not support creating shortcuts of other apps, and showing their icons?
The ShortcutInfo cannot be used in the new API (ShortcutManager), which is why I wrote this bug report.
You can't include all resources of all apps on the play store on your app. It's impossible. Apps get updated, added, and removed all the time on the Play Store.
What you are suggesting is not possible.
Suppose I want to create a shortcut to Gmail app using the new API, what would I choose to do? If I choose a bitmap, it will stay this way no matter if the Gmail app gets updated with new icon. Not only that, but on previous API, I didn't even need to decode the bitmap.
Please, always provide alternatives to existing features in case they need to be replaced. It can't be that I had this feature on previous versions, that I had on my app, and now I can't. It wasn't even marked as "for debug purposes" or "not for use on third party apps". This was a 100% legit API. It should have a good alternative API.
Description
OSR1.170720.005
* What device are you using? (for example, Nexus 6P)
Emulator
* What are the steps to reproduce the problem? (Please provide the minimal reproducible test case.)
Try to make a code that will put a shortcut with an icon of the destination app.
For example, to the settings app of the OS.
In my case, I tried to make one to the languages screen of the settings app:
Intent shortcutIntent = new Intent();
shortcutIntent.setAction(Intent.ACTION_MAIN);
String fullPathToActivity = "com.android.settings.Settings$LocalePickerActivity";
String packageName = "com.android.settings";
shortcutIntent.setClassName(packageName, fullPathToActivity);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
try {
int iconRes = context.getPackageManager().getActivityInfo(new ComponentName(packageName, fullPathToActivity), 0).icon;
//both of those failed :
//Uri path = resourceToUri(MainActivity.this,packageName,iconRes);
//Uri path=Uri.parse("android.resource://" + packageName + "/" + iconRes);
ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, getPackageName())
.setIcon(IconCompat.createWithContentUri(path))
.//setIcon(IconCompat.createWithResource(context, android.R.drawable.star_big_on))
.setShortLabel("languages")
.setIntent(shortcutIntent)
.build();
ShortcutManagerCompat.requestPinShortcut(context, pinShortcutInfo, null);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
public static Uri resourceToUri(Context context,String packageName, int resID) throws NameNotFoundException {
final Resources resources = context.getPackageManager().getResourcesForApplication(packageName);
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
resources.getResourcePackageName(resID) + '/' +
resources.getResourceTypeName(resID) + '/' +
resources.getResourceEntryName(resID));
}
* Issue Category e.g. Framework (platform), NDK (platform), Hardware (CPU, GPU, Sensor, Camera), ART (platform), Runtime Permissions etc
Framework
* What was the expected result?
To be able to put an icon of the destination activity of another app, as was possible before using EXTRA_SHORTCUT_ICON_RESOURCE :
This means that we could use the image that is inside another app, to be used to create a shortcut to it.
Example:
ShortcutIconResource shortcutIconResource = new Intent.ShortcutIconResource();
shortcutIconResource.packageName = packageName;
shortcutIconResource.resourceName = iconResourceName;
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIconResource);
* What was the actual result?
I don't think it's possible anymore. Maybe it's only possible by first getting the bitmap of the icon, but using the resource itself isn't.
The weird thing is that the docs say I should look at:
createShortcutResultIntent(ShortcutInfo)
But, this seems to belong to the launcher app (the receiver of the request), and not the one who triggered the creation of the app shortcut, as used by calling "requestPinShortcut" .
Trying to use any solution of URI gave me this exception:
java.lang.IllegalArgumentException: Unsupported icon type: only the bitmap and resource types are supported
Attached sample code to play with.