Android 开发之系统应用Launcher详解,简单添加和删除快捷方式及常见问题
2012-08-13 14:30
1051 查看
转载自:/article/1875840.html
1.. Launcher是什么?
1.1 Launcher是系统启动后加载的第一个应用程序
1.2 Launcher是其他应用程序的入口
2.Launcher的构成:
3. 主体四大组件的区别:
ShortCut: 应用程序的快捷方式
Appwidget:桌面小部件,图形不规则
LiveFolder: 文件夹
以ContentProvider的形式展示应用中特定数据的集合
WallPaper: 壁纸
预览图如下:
4. 通过按钮添加或者删除应用程序的快捷方式Demo:
Intent.EXTRA_SHORTCUT_INTENT,
布局文件:
Main.xml
[java] view
plaincopy
<?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
[java] view
plaincopy
<?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">
<intent-filter >
<!-拦截添加快捷方式,显示土司->
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
</intent-filter>
</activity>
</application>
</manifest>
LancherDemoActivity;
[java] view
plaincopy
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(<span style="color:#FF0000;">"com.android.action.test"</span>));
//发送广播
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(<span style="color:#FF0000;">"com.android.action.test"</span>));
sendBroadcast(shortcut);
}
});
}
}
注意事项: 在设置 EXTRA_SHORTCUT_INTENT时,添加和删除快捷方式的这个INTENT对象的ACTION属性必须设置为相同内容,才能声明删除和创建的快捷方式是一个,进行绑定,
否则删除无法生效
Android 开发之系统应用Launcher详解,简单添加和删除快捷方式及常见问题
1.. Launcher是什么?1.1 Launcher是系统启动后加载的第一个应用程序
1.2 Launcher是其他应用程序的入口
2.Launcher的构成:
3. 主体四大组件的区别:
ShortCut: 应用程序的快捷方式
Appwidget:桌面小部件,图形不规则
LiveFolder: 文件夹
以ContentProvider的形式展示应用中特定数据的集合
WallPaper: 壁纸
预览图如下:
4. 通过按钮添加或者删除应用程序的快捷方式Demo:
Intent.EXTRA_SHORTCUT_INTENT,
布局文件:
Main.xml
[java] view
plaincopy
<?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
[java] view
plaincopy
<?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">
<intent-filter >
<!-拦截添加快捷方式,显示土司->
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
</intent-filter>
</activity>
</application>
</manifest>
LancherDemoActivity;
[java] view
plaincopy
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(<span style="color:#FF0000;">"com.android.action.test"</span>));
//发送广播
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(<span style="color:#FF0000;">"com.android.action.test"</span>));
sendBroadcast(shortcut);
}
});
}
}
注意事项: 在设置 EXTRA_SHORTCUT_INTENT时,添加和删除快捷方式的这个INTENT对象的ACTION属性必须设置为相同内容,才能声明删除和创建的快捷方式是一个,进行绑定,
否则删除无法生效
相关文章推荐
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- [高级]Android Launcher研究(一)-----------图文详解手把手教你在Windows环境下下载Android源码(Launcher为例)Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android Launcher开发(五)添加应用程序桌面快捷方常见问题及解决方案
- Android Launcher桌面应用快捷方式的开发
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android开发:应用启动后自动创建桌面快捷方式(三星机常见)
- Android Launcher开发(五)添加应用程序桌面快捷方常见问题及解决方案
- Android 添加删除应用快捷方式
- Android Launcher桌面应用快捷方式的开发
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android Launcher桌面应用快捷方式的开发
- Android Launcher桌面应用快捷方式的开发
- Android Launcher开发(六)通过分析Laucher源码整理添加快捷方式的思路