How does Android create desktop shortcuts

Android desktop shortcut overview: @ h_ 301_ 5 @ creating a desktop shortcut is equivalent to creating an entry for a program, just as our program will automatically create an icon to the desktop after installation. In fact, creating a desktop shortcut is similar to creating a program entry, but to create a QQ friend's session shortcut like a QQ session, you have to dynamically create icons and names.

1. First of all, permission is essential

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />@H_ 301_ 5@

2. Then configure in your project configuration file

This activity is the one you want to jump to after clicking the shortcut

3. Then is the method you want to create a shortcut.

The code is as follows:

The importance of this line of code is that if there is no such line, when you click this shortcut and jump, it will directly jump to the top of the application stack (if the specified activity is at the top of the stack, it will not jump to it, but will be destroyed) rather than the specified activity (when this attribute is not added at the beginning, it will not jump to the specified activity).

shortcutIntent. setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);@ H_ 301_ 5@

If you want to dynamically add pictures, that is, when creating shortcuts, get pictures on the network to set their shortcut pictures, use

// Intent. EXTRA_ SHORTCUT_ Icon is the bitmap object shortcut putExtra(Intent.EXTRA_SHORTCUT_ICON,bitmap);@ H_ 301_ 5@

In this line of code, you can request the network picture, convert it to bitmap and set it in.

OK, this completes the dynamic creation of shortcuts.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>