1..Launcher是什么?
1.1Launcher是系统启动后加载的第一个应用程序
1.2Launcher是其他应用程序的入口
2.Launcher的构成:
3. 主体四大组件的区别:
ShortCut:应用程序的快捷方式
Appwidget:桌面小部件,图形不规则
LiveFolder:文件夹
以ContentProvider的形式展示应用中特定数据的集合
WallPaper:壁纸
预览图如下:
4. 通过按钮添加或者删除应用程序的快捷方式Demo:
Intent.EXTRA_SHORTCUT_INTENT,
布局文件:
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/BT_InstallShortCurt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Install ShortCurt" />
<Button
android:id="@+id/BT_UnInstallShortCurt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="UnInstall ShortCurt" />
</LinearLayout>
清单文件Mainifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itheima.lancher"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<!-- 该权限为系统自定义权限 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".LancherDemoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShortCutActivity">
<!-若希望在长按Menu键,添加快捷方式中出现应用条目,则需要加入以下内容->
<intent-filter ><action android:name="android.intent.action.CREATE_SHORTCUT"/> </intent-filter> </activity> </application></manifest>
LancherDemoActivity;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class LancherDemoActivity extends Activity {
private Button button1;
private Button button2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1 = (Button) findViewById(R.id.BT_InstallShortCurt);
button2 = (Button) findViewById(R.id.BT_UnInstallShortCurt);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
addShortCurt2DeskTop();
}
/**
* 添加桌面快捷方式
*/
private void addShortCurt2DeskTop() {
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TonyAutoShortCut");
shortcut.putExtra("duplicate", false); //不允许重复创建
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(LancherDemoActivity.this, R.drawable.beauty));
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(LancherDemoActivity.this,LancherDemoActivity.class).setAction("com.android.action.test"));
//发送广播
sendBroadcast(shortcut);
}
});
/**
* 删除桌面快捷方式
*/
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
deleteShortCurt2DeskTop();
}
private void deleteShortCurt2DeskTop() {
Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
//快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TonyAutoShortCut");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(LancherDemoActivity.this,LancherDemoActivity.class).setAction("com.android.action.test"));
sendBroadcast(shortcut);
}
});
}
}
注意事项: 在设置 EXTRA_SHORTCUT_INTENT时,添加和删除快捷方式的这个INTENT对象的ACTION属性必须设置为相同内容,才能声明删除和创建的快捷方式是一个,进行绑定,
否则删除无法生效
分享到:
相关推荐
Android中实现Launcher功能之添加快捷方式
Androidlauncher开发.pdf
android手把手教你开发launcher(AndroidStudio版) pdf文档
此资源是在安卓巴士交会上王鹏工程师分享的Launcher3的原理及二次开发pdf。文中介绍啦Launcher3的框架和主要流程,能给从事Lauuncher3开发和桌面定制的开发人员启迪。特此分享出来。
android手把手教你开发launcher.pdf
里面包含了"Android_Launcher应用开发.pdf"和本书提供的"示例代码",需要有一定的Android基础,适合Android进阶
本书以Launcher为解析核心,全面深入地介绍了Launcher的清单、应用程序组件、资源配置、UI组件以及Launcher的操作等,包含了整个桌面的体系和技巧。本书语言通俗易懂,解析全面,有利于读者理解整个Launcher桌面的...
本文实例讲述了Android实现向Launcher添加快捷方式的方法。分享给大家供大家参考。具体如下: 当我们在应用程序Launcher的桌面空白处长按触摸时,会出现一个对话框,提示选择要添加的桌面组件,如下图所示 选择快捷...
android源码的Launcher详细解析,分析Launcher的运行机制
Android 取消系统默认 launcher3的home属性,保证第三方的launcher正常使用.patch
Android 5.0 版本及以上可能会出现因为相同权限声明而不能安装的问题 如果你想要可以在Eclipse编译的版本,可以看这个tag: GOODBYE_ECLIPSE 我写了几篇博客来讲解Launcher3桌面什么的,有兴趣的可以看看这里: ...
android 9.0 10.0Launcher3中 Hotseat 添加apps button功能 点击apps 进入app列表界面
android系统launcher
手把手教你开发定制launcher,一个比较简单的launcher开发!
Android应用源码之Launcher2_源码
Android 8.0 Launcher开发指南.
android 系统的启动页如何实现我们可以去探索
launcher 开发 在这里 我们继承了launcher 开发前人经验 一同学习
launcher添加动态时钟和动态日历. CalendarScript.java ClockScript.java IconScript.java 是新加入的类 其它的是launcher3本身有的 对比过去就好.在代码中搜索"动态时钟显示"就能找到我加入的东西
Android系统桌面Launcher3源码,可直接在Android Studio中编译。