Summary of common methods of creating desktop shortcuts by Android programming [2 methods]

This article describes the common methods of creating desktop shortcuts by Android programming. Share with you for your reference, as follows:

There are two cases when Android generates shortcuts on the desktop. One is to generate shortcuts directly on the desktop; One is to long press the desktop and generate it in the pop-up shortcut menu.

Talk about generating directly on the desktop. Personally, I think this is more refreshing. Since it's all shortcuts, why hide another layer? Of course, I prefer the second one with a clean desktop.

The first is to send a request to the launcher in the form of broadcast to generate a shortcut.

Find registration information about this on the Internet.

It can be seen that permission is required to create a shortcut on the desktop:

android:permission="com.android.launcher.permission.INSTALL_SHORTCUT。

Therefore, in our manifest.xml file, we need to add the following paragraph:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

The following is the implementation of the code layer:

Suppose I create a shortcut method in an activity: createshortcut();

2、 Long press the desktop shortcut that pops up on the desktop to create

On the first page, we talked about how to generate shortcuts directly on the desktop. Now let's talk about how to add them to a shortcuts list, which is the thing that pops up when you long press the desktop.

First, when registering an activity, you need to add an action as android.intent.action.create_ The intentfilter. Of shortcut is as follows:

The next step is to set the icon, name, event and other properties of the shortcut. Here, Android provides a special method to generate charts.

PS: for the properties and functions related to the androidmanifest.xml file, please refer to the online tools of this website:

Description of Android manifest functions and permissions: http://tools.jb51.net/table/AndroidManifest

More readers interested in Android related content can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills and summary of Android control usage

I hope this article will help you in Android programming.

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
分享
二维码
< <上一篇
下一篇>>