qq_2790289459的博客

专注于Android开发学习

Launcher的简单介绍

Launcher

什么是Launcher

    Launcher是安卓系统中的桌面启动器,安卓系统的桌面UI统称为LauncherLauncher的启动实际上就是启动一个ActivityLauncher.java)。

当我们点击手机的home键时,实际上就是启动桌面管理器,会启动LaunCher.java Activity

我们也可以将自己的应用程序中的Activity作为Launcher,只要在我们的Activity注册时,在意图过滤器中添加categoryandroid:name="android.intent.category.HOME"android:name="android.intent.category.DEFAULT"这样当我们点击home键时会弹窗让我们选择开启那个Lanuncher

   

清单文件

<application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

        <activity

            android:name=".MainActivity"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>

                <category android:name="android.intent.category.HOME"/> 

                <category android:name="android.intent.category.DEFAULT"/>

            </intent-filter>

        </activity>

</application>

 

 

 

//查询所有的应用程序并显示 ResolveInfo的使用和获取所有安装程序列表的实现

Activity:

 

publicclass ShowDevelopments extends Activity {

         private GridView show_developments;

         private List<ResolveInfo> info;

         @Override

         protected void onCreate(BundlesavedInstanceState) {

                   super.onCreate(savedInstanceState);

                   setContentView(R.layout.activity_developments);

                   show_developments=(GridView)findViewById(R.id.show_developments);

                   info=newArrayList<ResolveInfo>();

                   getData();

                   MyAdapter adapter=newMyAdapter(info);

                   show_developments.setAdapter(adapter);

                   show_developments.setOnItemClickListener(newAdapterView.OnItemClickListener() {

 

                            @Override

                            public voidonItemClick(AdapterView<?> parent, View view,

                                               intposition, long id) {

                                     start(position);

                            }

                   });

         }

         /**

          * 界面跳转的方法:ComponentName的使用

          */

         private void start(int i){

                   ResolveInfoinfo = this.info.get(i); 

        //该应用的包名 

        String pkg =info.activityInfo.packageName; 

        //应用的主activity 

        String cls =info.activityInfo.name; 

        ComponentName componet = newComponentName(pkg, cls); 

        Intent intent = new Intent(); 

        intent.setComponent(componet); 

        startActivity(intent);

         }

         /**

          * 获取所有的安装的应用程序

          */

         private void getData(){

                   IntentmainIntent = new Intent(Intent.ACTION_MAIN, null); 

            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

//          new ImageView(ShowDevelopments.this); 

            info = getPackageManager().queryIntentActivities(mainIntent, 0);

         }

         private class MyAdapter extendsBaseAdapter{

                   privateList<ResolveInfo> info;

                   private LayoutInflaterinflater;

                   privateMyAdapter(List<ResolveInfo> info){

                            this.info=info;

                            inflater=getLayoutInflater();

                   }

                   @Override

                   public int getCount() {

                            returninfo!=null?info.size():0;

                   }

 

                   @Override

                   public Object getItem(intposition) {

                            returninfo.get(position);

                   }

 

                   @Override

                   public long getItemId(intposition) {

                            return position;

                   }

 

                   @Override

                   public View getView(intposition, View convertView, ViewGroup parent) {

                            View[] view=newView[2];

                            if(convertView==null){

                                     convertView=inflater.inflate(R.layout.item_showdata,null);

                                     view[0]=convertView.findViewById(R.id.show_image);

                                     view[1]=convertView.findViewById(R.id.chengxu);

                                     convertView.setTag(view);

                            }

                            view=(View[])convertView.getTag();

                            ((TextView)view[1]).setText(info.get(position).loadLabel(getPackageManager()));

                            ((ImageView)view[0]).setImageDrawable((info.get(position).loadIcon(getPackageManager())));

                            return convertView;

                   }                

         }

}

 

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jiuweitianhu_12345/article/details/52371589
个人分类: Android
上一篇一个应用启动另一个应用+开机启动应用
下一篇系统安装
想对作者说点什么? 我来说一句

android launcher demo

2015年09月14日 1.64MB 下载

android启动

2017年12月12日 13.26MB 下载

android launcher

2015年08月07日 460KB 下载

没有更多推荐了,返回首页

关闭
关闭