1..Launcher是什么?
1.1Launcher是系统启动后加载的第一个应用程序
1.2Launcher是其他应用程序的入口
2.Launcher的构成:
3. 主体四大组件的区别:
ShortCut:应用程序的快捷方式
Appwidget:桌面小部件,图形不规则
LiveFolder:文件夹
以ContentProvider的形式展示应用中特定数据的集合
WallPaper:壁纸
预览图如下:
4.通过按钮添加或者删除应用程序的快捷方式Demo:
Intent.EXTRA_SHORTCUT_INTENT,
布局文件:
Main.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns: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="InstallShortCurt"/>
- <Button
- android:id="@+id/BT_UnInstallShortCurt"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="UnInstallShortCurt"/>
- </LinearLayout>
清单文件Mainifest.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <manifestxmlns:android="http://schemas.android.com/apk/res/android"
- package="com.itheima.lancher"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdkandroid:minSdkVersion="8"/>
- <!--该权限为系统自定义权限-->
- <uses-permissionandroid:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
- <uses-permissionandroid: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>
- <actionandroid:name="android.intent.action.MAIN"/>
- <categoryandroid:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- <activityandroid:name=".ShortCutActivity">
- <intent-filter>
- <!-拦截添加快捷方式,显示土司->
- <actionandroid:name="android.intent.action.CREATE_SHORTCUT"/>
- </intent-filter>
- </activity>
- </application>
- </manifest>
LancherDemoActivity;
- importandroid.app.Activity;
- importandroid.content.ComponentName;
- importandroid.content.Intent;
- importandroid.os.Bundle;
- importandroid.view.View;
- importandroid.view.View.OnClickListener;
- importandroid.widget.Button;
- publicclassLancherDemoActivityextendsActivity{
- privateButtonbutton1;
- privateButtonbutton2;
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- button1=(Button)findViewById(R.id.BT_InstallShortCurt);
- button2=(Button)findViewById(R.id.BT_UnInstallShortCurt);
- button1.setOnClickListener(newOnClickListener(){
- publicvoidonClick(Viewv){
- addShortCurt2DeskTop();
- }
- /**
- *添加桌面快捷方式
- */
- privatevoidaddShortCurt2DeskTop(){
- Intentshortcut=newIntent("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,newIntent(LancherDemoActivity.this,LancherDemoActivity.class).setAction(<spanstyle="color:#FF0000;">"com.android.action.test"</span>));
- //发送广播
- sendBroadcast(shortcut);
- }
- });
- /**
- *删除桌面快捷方式
- */
- button2.setOnClickListener(newOnClickListener(){
- publicvoidonClick(Viewv){
- deleteShortCurt2DeskTop();
- }
- privatevoiddeleteShortCurt2DeskTop(){
- Intentshortcut=newIntent("com.android.launcher.action.UNINSTALL_SHORTCUT");
- //快捷方式的名称
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,"TonyAutoShortCut");
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,newIntent(LancherDemoActivity.this,LancherDemoActivity.class).setAction(<spanstyle="color:#FF0000;">"com.android.action.test"</span>));
- sendBroadcast(shortcut);
- }
- });
- }
- }
注意事项: 在设置 EXTRA_SHORTCUT_INTENT时,添加和删除快捷方式的这个INTENT对象的ACTION属性必须设置为相同内容,才能声明删除和创建的快捷方式是一个,进行绑定,
否则删除无法生效
1..Launcher是什么?
1.1Launcher是系统启动后加载的第一个应用程序
1.2Launcher是其他应用程序的入口
2.Launcher的构成:
3. 主体四大组件的区别:
ShortCut:应用程序的快捷方式
Appwidget:桌面小部件,图形不规则
LiveFolder:文件夹
以ContentProvider的形式展示应用中特定数据的集合
WallPaper:壁纸
预览图如下:
4.通过按钮添加或者删除应用程序的快捷方式Demo:
Intent.EXTRA_SHORTCUT_INTENT,
布局文件:
Main.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns: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="InstallShortCurt"/>
- <Button
- android:id="@+id/BT_UnInstallShortCurt"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="UnInstallShortCurt"/>
- </LinearLayout>
清单文件Mainifest.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <manifestxmlns:android="http://schemas.android.com/apk/res/android"
- package="com.itheima.lancher"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdkandroid:minSdkVersion="8"/>
- <!--该权限为系统自定义权限-->
- <uses-permissionandroid:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
- <uses-permissionandroid: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>
- <actionandroid:name="android.intent.action.MAIN"/>
- <categoryandroid:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- <activityandroid:name=".ShortCutActivity">
- <intent-filter>
- <!-拦截添加快捷方式,显示土司->
- <actionandroid:name="android.intent.action.CREATE_SHORTCUT"/>
- </intent-filter>
- </activity>
- </application>
- </manifest>
LancherDemoActivity;
- importandroid.app.Activity;
- importandroid.content.ComponentName;
- importandroid.content.Intent;
- importandroid.os.Bundle;
- importandroid.view.View;
- importandroid.view.View.OnClickListener;
- importandroid.widget.Button;
- publicclassLancherDemoActivityextendsActivity{
- privateButtonbutton1;
- privateButtonbutton2;
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- button1=(Button)findViewById(R.id.BT_InstallShortCurt);
- button2=(Button)findViewById(R.id.BT_UnInstallShortCurt);
- button1.setOnClickListener(newOnClickListener(){
- publicvoidonClick(Viewv){
- addShortCurt2DeskTop();
- }
- /**
- *添加桌面快捷方式
- */
- privatevoidaddShortCurt2DeskTop(){
- Intentshortcut=newIntent("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,newIntent(LancherDemoActivity.this,LancherDemoActivity.class).setAction(<spanstyle="color:#FF0000;">"com.android.action.test"</span>));
- //发送广播
- sendBroadcast(shortcut);
- }
- });
- /**
- *删除桌面快捷方式
- */
- button2.setOnClickListener(newOnClickListener(){
- publicvoidonClick(Viewv){
- deleteShortCurt2DeskTop();
- }
- privatevoiddeleteShortCurt2DeskTop(){
- Intentshortcut=newIntent("com.android.launcher.action.UNINSTALL_SHORTCUT");
- //快捷方式的名称
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,"TonyAutoShortCut");
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,newIntent(LancherDemoActivity.this,LancherDemoActivity.class).setAction(<spanstyle="color:#FF0000;">"com.android.action.test"</span>));
- sendBroadcast(shortcut);
- }
- });
- }
- }
注意事项: 在设置 EXTRA_SHORTCUT_INTENT时,添加和删除快捷方式的这个INTENT对象的ACTION属性必须设置为相同内容,才能声明删除和创建的快捷方式是一个,进行绑定,
否则删除无法生效