I'm creating a pinned shortcut of my app launcher icon for Android O device (either emulator or physical device) and found strange behaviour. My code looks like this:
@TargetApi(Build.VERSION_CODES.O)
private void createPinnedShortcut(Context context) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
if (shortcutManager.isRequestPinShortcutSupported()) {
Intent intent= MainActivity.getLaunchIntent(this);
intent.setAction(Intent.ACTION_VIEW);
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, "my_shortcut_id")
.setShortLabel(context.getString(R.string.my_app_description))
.setLongLabel(context.getString(R.string.my_app_long_description))
.setIcon(Icon.createWithResource(context, R.mipmap.my_app_icon))
.setIntent(intent)
.build();
shortcutManager.requestPinShortcut(shortcut, null);
} else
Toast.makeText(context, "Pinned shortcuts are not supported!", Toast.LENGTH_SHORT).show();
}
}
Everything works, but the launcher icon on the home screen is duplicated:
There is a normal icon, but on right lower corner it placed yet another copy of the icon (about 30-40% smaller).
My icon resources are in res/mipmap-*dpi*
folders
Any hints, clues?
Update
Answering to comments:
1) AndroidManifest under ./build/manifests/debug
looks like:
<activity
android:name="ru.ivanovpv.cellboxkeeper.android.MainActivity"
android:exported="true"
android:label="@string/cellboxkeeper"
android:theme="@style/DefaultActivityTheme.Light"
android:windowSoftInputMode="adjustResize" >
<layout
android:defaultHeight="800dp"
android:defaultWidth="480dp"
android:gravity="top|end"
android:minHeight="320dp"
android:minWidth="240dp" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> <!-- handle cbx files -->
<intent-filter
android:icon="@mipmap/cellboxkeeper"
android:label="@string/cellboxkeeper"
android:logo="@mipmap/cellboxkeeper" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.cbx"
android:scheme="content" />
</intent-filter>
<!-- receive files from android share intent -->
<intent-filter
android:icon="@mipmap/cellboxkeeper"
android:label="@string/addToCellboxKeeper" >
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
2) There's not any folder like: mipmap-*-v26
. Here's screenshot of folders in real apk. All icons in folders are normal (w/o duplication).
Any other versions?
I found solution, key is attribute android:logo
:
<intent-filter
android:icon="@mipmap/cellboxkeeper"
android:label="@string/cellboxkeeper"
android:logo="@mipmap/cellboxkeeper" >
<action android:name="android.intent.action.VIEW" />
Deleting line with android:logo
fixes duplication issue.
Hope, someone and sometimes will use and understands what's goin on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With