android系统的homescreen 就是一个系统的launcher,由它来负责启动其他的Activity。
系统launcher的Activity

            
  1. <activity 
  2.     android:name="com.android.launcher2.Launcher" 
  3.     android:launchMode="singleTask" 
  4.     android:clearTaskOnLaunch="true" 
  5.     android:stateNotNeeded="true" 
  6.     android:theme="@style/Theme" 
  7.     android:screenOrientation="nosensor" 
  8.     android:windowSoftInputMode="stateUnspecified|adjustPan"> 
  9.     <intent-filter> 
  10.         <action android:name="android.intent.action.MAIN" /> 
  11.         <category android:name="android.intent.category.HOME" />  
  12.         <category android:name="android.intent.category.DEFAULT" /> 
  13.         <category android:name="android.intent.category.MONKEY"/> 
  14.     intent-filter> 
  15. activity> 


首先launcher使用pickShortcut()方法调用pickActivity对象,pickActivity对象调用check Intent filter() and chose item(),返回一个Intent对象。如图
    


选中图标之后,会在HomeScreen上添加一个图标。

2.怎样创建android桌面图标,代码如下
    在androd manifest.xml的Activity标签中添加创建图标的动作

            
  1. <action android:name="android.intent.action.CREATE_SHORTCUT"/> 
    然后在Activity中创建一个Intent对象
            
  1.   Intent addShortcut; 
  2. if(getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) 
  3.     addShortcut = new Intent(); 
  4.     addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式"); 
  5.     addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher)); 
  6.     addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(LauncherSimpleActivity.this,MainActivity.class)); //点击图标启动的Activity 
  7.     setResult(RESULT_OK, addShortcut); 
  8. }else { 
  9.     setResult(RESULT_CANCELED); 
  10. finish(); //添加完成之后销毁这个Activity 

更多相关文章

  1. 类和 Json对象
  2. gson使用在android使用例子
  3. Android(安卓)封装json数据
  4. Android(安卓)Studio修改apk命名
  5. Android(安卓)Widget 小部件(三) 在Activity中添加Widget
  6. android 自带图标介绍
  7. android SQLite数据库基本操作示例
  8. android 蓝牙通讯
  9. android文件下载

随机推荐

  1. Android(安卓)Studio—— 关于在Android(
  2. Android特色开发之账户管理
  3. Android开发规范,性能优化
  4. 【译】Android主题动态切换开源库Prism基
  5. Android常用的数据结构
  6. 我和Android娘情缘
  7. Google计划开发开源WebKit内核Android浏
  8. Android(安卓)AIDL入门例子
  9. android logcat
  10. android 数字证书