How to enable the appwidget to be automatically added to home screen after it is started

Source: Internet
Author: User
Tags home screen

Recently, I have been studying the system source code of android2.2. Due to the project requirements, a project requirement is to enable the appwidget to be automatically added to the home screen after it is started.

Now, I am done. Let's talk about my practices.

I modified the theme source code of lanucher2. In fact, it is quite simple to think about it. First, put the APK package of the appwidget you want to display in the system/APP directory. Here, I will explain two ways:

1. Use the ADB command to push to/system/APP. Note that because the initial permission of the system directory is read-only, you must change the system to read/write, ADB remount
Click

Re-mount the partition command to make the system partition from read-only to readable and writable.

2. You can directly put the APK package of the appwidget ~ /Device/You-productname/prebuilt/packages/directory, and then make, so that the appwidget APK package will ~ /Out/target/product/imx51_bbg/system/APP directory. However, this method varies depending on the compilation rules. This method is for reference only.

If you want to install widgets that appear in the menu-> widgets, you can put the java files of widgets into the widgets folder under the underlying frameworks folder, then, make some modifications to the files in the appwidget folder. For how to make the modifications, the website also provides detailed instructions so that they can be added like system widgets.

After installing the widget APK, you can start to modify the theme source code.

The following describes two methods. One is to directly modify the default_workspace.xml file in the/RES/XML folder. The modification method is as follows:

<Appwidget
Launcher: packagename = "..." // packagename of the widget
Launcher: classname = "..." // name of the pluer class that implements the widget.
Launcher: Container = "..." // place (only desktop)
Launcher: screen = "..." // The number of screens to be placed on.
Launcher: x = "..." // The X location of the disk.
Launcher: Y = "..." // y position
Launcher: Spanx = "..." // number of cells in the X direction
Launcher: spany = "..."/> // number of cells in the Y direction

The second is to add clockwidget in the same way under launcherprovider, and then modify it in the default_workspace.xml file under method 1/RES/XML.

After the modification, push the APK package generated by the topic to/system/APP as a push widget.

In this case, you can see the implementation effect. If you need to perform multiple tests, first Delete the/data/installed topic package name/database/launcher. DB database.
To prevent the existence of cached data.

If you do not see the effect, there may be two possible causes, especially when testing on the simulator. What's going on? The Android system treats your launcher as a non-secure mode (the issafemode is false). You can use this code in launchermodel. the loadworkspace method in Java is found, so the system will delete the pre-added widgets when your launcher starts. The Code is as follows:

If (! Issafemode & (provider = NULL | provider. provider = NULL | <br/> provider. provider. getpackagename () = NULL) {<br/> log. E (TAG, "deleting widget that isn't installed anymore: Id =" <br/> + ID + "appwidgetid =" + appwidgetid); <br/> itemstoremove. add (ID); <br/>}

So we failed to load the widget.

 

If we burn a version and place it on the terminal device, we will not see this problem.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.