Develop an Android desktop

Source: Internet
Author: User

The text of this text connection is: http://blog.csdn.net/freewebsys/article/details/53363731 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys

1, about Lancher

To develop a desktop of their own, as programmers, feel that a lot of applications are secretly running traffic.
Develop a desktop program, then resident system service, timed check service.
Monitor other application networks in the system. Integrate some of the common functions.
Make a voice service for flying. Implement some simple human-computer interaction.
Refer to a buddy who wrote:
http://blog.csdn.net/sljjyy/article/details/11927713

2. Modify the configuration file

Add two lines to the Androidmanifest.xml configuration file.

        <activity android:name=". Mainactivity ">            <intent-filter>                <!--Add Lancher configuration --                <category android:name="Android.intent.category.HOME" />                <category android:name="Android.intent.category.DEFAULT" />                <action android:name="Android.intent.action.MAIN" />                <category android:name="Android.intent.category.LAUNCHER" />            </intent-filter>        </activity>

The default activity program then becomes the desktop. By the time you press home.
A selection box will pop up to select the desktop.

3, optimize

Search All Apps

newnull);        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);        new ImageView(MainActivity.this);        0);        ifnull) {            for (ResolveInfo resolveInfo : apps) {                Log.v(TAG, resolveInfo.toString());            }        }

Displays the returned app to the main interface.
Implement a Baseadapter class. Implement the GetView method.

ResolveInfo info = Apps. Get(i);View Convertview = Layoutinflater. from(mcontent). Inflate(R. Layout. Text_img_view, NULL);ImageView image = (ImageView) convertview. Findviewbyid(R. ID. Image);TextView Text = (TextView) convertview. Findviewbyid(R. ID. Text);Set up text and pictures. Text. SetText(Info. Loadlabel(Getpackagemanager ()));Image. Setimagedrawable(Info. Activityinfo. LoadIcon(Getpackagemanager ()));Convertview. Setscaletype(ImageView. ScaleType. FIT_center);Use DP for parameter setting.            For resolution adaptation. Convertview. Setlayoutparams(New GridView. Layoutparams(int) mresources. Getdimension(R. Dimen. App_width), (int) mresources. Getdimension(R. Dimen. App_height)));Returns a picture-and-text blend. Return Convertview;

Defines a layout

<?xml version= "1.0" encoding= "Utf-8"?><linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"  Android:layout_width="Match_parent"android:layout_height="Match_parent"  Android:orientation="vertical">                <imageview  android:id
      = "@+id/image"  android:layout_width  =< Span class= "Hljs-value" > "50DP"  android:layout_height  =" 50DP " android:layout_gravity  =" Center_horizontal "/>     <TextViewandroid:id= "@+id/text"android:layout_width="Match_ Parent "android:layout_height=" Wrap_content "android:gravity=" center " / >                                </linearlayout>

Above is the picture, below is the text.
Also defines the width and height

<resources>    <dimen name="app_width">90dp</dimen>    <dimen name="app_height">90dp</dimen></resources>

Operating effect:

It's close.
Finally open under Settings. Wallpaper What's. It's all the same.

4, all code
 PackageCom.demo.lanchertest;ImportAndroid.content.ComponentName;ImportAndroid.content.Context;ImportAndroid.content.Intent;ImportAndroid.content.pm.ResolveInfo;ImportAndroid.content.res.Resources;ImportAndroid.net.Uri;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.AbsListView;ImportAndroid.widget.AdapterView;ImportAndroid.widget.BaseAdapter;ImportAndroid.widget.GridView;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView;ImportCom.google.android.gms.appindexing.Action;ImportCom.google.android.gms.appindexing.AppIndex;Importcom.google.android.gms.appindexing.Thing;ImportCom.google.android.gms.common.api.GoogleApiClient;ImportJava.security.AccessControlContext;ImportJava.util.List;Import StaticJava.security.AccessController.getContext; Public  class mainactivity extends appcompatactivity {     Public Static FinalString TAG ="Lancher";@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);//Load app app. Loadapps (); GridView GridView = (GridView) Findviewbyid (r.id.apps_list);//Set the default adapter. Mcontent = Getapplicationcontext ();        Mresources = Getresources (); Gridview.setadapter (NewAppsadapter ());//Gridview.setonitemclicklistener (Clicklistener); }PrivateAdapterview.onitemclicklistener Clicklistener =NewAdapterview.onitemclicklistener () {@Override         Public void Onitemclick(adapterview<?> Adapterview, view view,intILongL) {ResolveInfo info = apps.get (i);//Package name for the appString pkg = info.activityInfo.packageName;//Application of the main activity classString cls = Info.activityInfo.name; ComponentName componet =NewComponentName (pkg, CLS); Intent Intent =NewIntent ();            Intent.setcomponent (componet);        StartActivity (Intent); }    };PrivateList<resolveinfo> apps;PrivateResources mresources;PrivateContext mcontent;Private void Loadapps() {Intent mainintent =NewIntent (Intent.action_main,NULL); Mainintent.addcategory (Intent.category_launcher);NewImageView (mainactivity. This); Apps = Getpackagemanager (). Queryintentactivities (Mainintent,0);if(Apps! =NULL) { for(ResolveInfo Resolveinfo:apps)            {LOG.V (TAG, resolveinfo.tostring ()); }        }    } Public  class appsadapter extends baseadapter {         Public Appsadapter() {        }@Override         Public int GetCount() {returnApps.size (); }@Override         PublicObjectGetItem(inti) {returnApps.get (i); }@Override         Public Long Getitemid(inti) {returnI }@Override         PublicViewGetView(intI, view view, ViewGroup viewgroup) {ResolveInfo info = apps.get (i); View Convertview = Layoutinflater.from (mcontent). Inflate (R.layout.text_img_view,NULL);            ImageView image = (ImageView) Convertview.findviewbyid (r.id.image); TextView Text = (TextView) Convertview.findviewbyid (R.id.text);//Set text and pictures. Text.settext (Info.loadlabel (Getpackagemanager ())); Image.setimagedrawable (Info.activityInfo.loadIcon (Getpackagemanager ()));//Convertview.setscaletype (ImageView.ScaleType.FIT_CENTER);            //Use DP for parameter setting. For resolution adaptation. Convertview.setlayoutparams (NewGridview.layoutparams ((int) mresources.getdimension (R.dimen.app_width), (int) mresources.getdimension (r.dimen.app_height));//Returns a picture-and-text blend.             returnConvertview; }    }}

All code is only 130 lines. But it's interesting.

5, summary

The text of this text connection is: http://blog.csdn.net/freewebsys/article/details/53363731 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys

It's interesting to develop a custom desktop.
I want to control it. A page shows how many apps, text size, icons.

Develop an Android desktop

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.