开发一个android桌面_第1页
开发一个android桌面_第2页
开发一个android桌面_第3页
开发一个android桌面_第4页
开发一个android桌面_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

开发一个android桌面1,关于lancher要开发一个自己的桌面,作为程序员,觉得好多的应用都在偷偷的跑流量。开发一个桌面程序,然后常驻系统服务,定时检查服务。对系统的其他应用网络进行监控。把一些常用的功能集成进来。做一个讯飞的语音服务。实现一些简单的人机交互。2,修改配置文件在AndroidManifest.xml配置文件中增加两行即可。<activityandroid:name=".MainActivity"><intent-filter><!--增加lancher配置--><categoryandroid:name="ent.category.HOME"/><categoryandroid:name="ent.category.DEFAULT"/><actionandroid:name="ent.action.MAIN"/><categoryandroid:name="ent.category.LAUNCHER"/></intent-filter></activity>然后这个默认的activity程序就成桌面了。按home的时候。会弹出一个选择框选择桌面。3,进行优化查询全部appIntentmainIntent=newIntent(Intent.ACTION_MAIN,null);mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);newImageView(MainActivity.this);apps=getPackageManager().queryIntentActivities(mainIntent,0);if(apps!=null){for(ResolveInforesolveInfo:apps){Log.v(TAG,resolveInfo.toString());}}把返回的app显示到主界面中。实现一个BaseAdapter类。实现getView方法。ResolveInfoinfo=apps.get(i);ViewconvertView=LayoutInflater.from(mContent).inflate(R.layout.text_img_view,null);ImageViewimage=(ImageView)convertView.findViewById(R.id.image);TextViewtext=(TextView)convertView.findViewById(R.id.text);//设置文字和图片。text.setText(info.loadLabel(getPackageManager()));image.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));//convertView.setScaleType(ImageView.ScaleType.FIT_CENTER);//使用dp进行参数设置。进行分辨率适配。convertView.setLayoutParams(newGridView.LayoutParams((int)mResources.getDimension(R.dimen.app_width),(int)mResources.getDimension(R.dimen.app_height)));//返回一个图文混合。returnconvertView;定义了一个layout<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/image"android:layout_width="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>上面是图片,下面是文字。还定义了宽度和高度<resources><dimenname="app_width">90dp</dimen><dimenname="app_height">90dp</dimen></resources>运行效果:很接近了。最后在设置下打开。壁纸啥的。就都一样了。4,全部代码packagecom.demo.lanchertest;importandroid.content.ComponentName;importandroid.content.Context;importandroid.content.Intent;importandroid.content.pm.ResolveInfo;importandroid.content.res.Resources;import.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;importmon.api.GoogleApiClient;importjava.security.AccessControlContext;importjava.util.List;importstaticjava.security.AccessController.getContext;publicclassMainActivityextendsAppCompatActivity{publicstaticfinalStringTAG="Lancher";@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(InstanceState);setContentView(R.layout.activity_main);//加载app应用。loadApps();GridViewgridView=(GridView)findViewById(R.id.apps_list);//设置默认适配器。mContent=getApplicationContext();mResources=getResources();gridView.setAdapter(newAppsAdapter());//gridView.setOnItemClickListener(clickListener);}privateAdapterView.OnItemClickListenerclickListener=newAdapterView.OnItemClickListener(){@OverridepublicvoidonItemClick(AdapterView<?>adapterView,Viewview,inti,longl){ResolveInfoinfo=apps.get(i);//该应用的包名Stringpkg=info.activityInfo.packageName;//应用的主activity类Stringcls=info.activityI;ComponentNamecomponet=newComponentName(pkg,cls);Intentintent=newIntent();intent.setComponent(componet);startActivity(intent);}};privateList<ResolveInfo>apps;privateResourcesmResources;privateContextmContent;privatevoidloadApps(){IntentmainIntent=newIntent(Intent.ACTION_MAIN,null);mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);newImageView(MainActivity.this);apps=getPackageManager().queryIntentActivities(mainIntent,0);if(apps!=null){for(ResolveInforesolveInfo:apps){Log.v(TAG,resolveInfo.toString());}}}publicclassAppsAdapterextendsBaseAdapter{publicAppsAdapter(){}@OverridepublicintgetCount(){returnapps.size();}@OverridepublicObjectgetItem(inti){returnapps.get(i);}@OverridepubliclonggetItemId(inti){returni;}@OverridepublicViewgetView(inti,Viewview,ViewGroupviewGroup){ResolveInfoinfo=apps.get(i);ViewconvertView=LayoutInflater.from(mContent).inflate(R.layout.text_img_view,null);ImageViewimage=(ImageView)convertView.findViewById(R.id.ima

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论