AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iaiai.activity" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="IaiaiActivity" android:label="@string/contact_title">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- 添加快捷键权限 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
</manifest>
main.xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/contactItems"
android:paddingBottom="5dip" android:paddingLeft="12dip"
android:paddingTop="5dip" android:paddingRight="12dip">
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/btn_create"
android:text="@string/create"></Button>
</LinearLayout>
IaiaiActivity.java类:
package com.iaiai.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class IaiaiActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn_create);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent addIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
Parcelable icon = Intent.ShortcutIconResource.fromContext(
IaiaiActivity.this, R.drawable.icon); // 获取快捷键的图标
Intent myIntent = new Intent(IaiaiActivity.this,
IaiaiActivity.class);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");// 快捷方式的标题
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 快捷方式的动作
sendBroadcast(addIntent);// 发送广播
}
});
}
}
分享到:
相关推荐
Selinux-篇4 标签 android版本(csdn)————程序
android 为应用程序创建快捷方式 可以在应用程序中任意位置添加该代码
Android三维程序设计——基于OpenGL ES的图形应用程序设计——(源码) 英文版《Learn-OpenGL-ES-Master》
Android数据库应用编程——为企业开发数据驱动Android应用 透彻讲述如何使用内容提供器共享数据、使用适配器显示数据以及使用Web服务传输数据,介绍集成应用程序和现有企业系统、保护数据以及同步数据的方法。通过...
安卓Android源码——快捷图标的创建与移除.zip
本文实例讲述了Android通过应用程序创建快捷方式的方法。分享给大家供大家参考。具体如下: Android 快捷方式是桌面最基本的组件。它用于直接启动某一应用程序的某个组件。 一般情况下,可以在Launcher的应用程序...
Android系统级深入开发——移植与调试 pdf
android 检查是否创建桌面快捷方式以及创建快捷方式
安卓Android源码——快捷图标的创建与移除.rar
还有几十个电子书和源代码 请点击我的名字 通通免费 希望大家给个好评 //**************// 都是最近半年收集的android 开发资料和源代码,挑选出好的给大家
移动操作系统原理与实践——基于Java语言的Android应用开发 目录 基础篇 第1章移动操作系统概论 1.1操作系统的原理与概念 1.1.1隐藏硬件细节 ...第3章第一个Android应用程序 3.1使用Android Studio工具创建项目
Android源码——应用程序自动更新源码.zip
动手学Android之十三——动起来例子程序,演示了android动画的方方面面,希望大家下载哦
[Android Studio应用开发——基础入门与应用实战][方欣,杨勃][电子课件]
安卓Android源码——应用程序自动更新源码.zip
安卓Android源码——应用程序自动更新源码.rar