日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android中程序向桌面和Launcher添加快捷方式

發布時間:2025/6/15 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android中程序向桌面和Launcher添加快捷方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ?最近感覺這個添加快捷方式挺有趣的,就查資料自己寫了個demo---簡單的例子,這個例子就是有兩個按鈕,點擊“將此程序添加到快捷方式”,則手機桌面增加一個快捷方式,同時launcher中也多了一個快捷方式,點擊退出,則提示:toast彈提示信息“退出程序”。知識梳理:Android平臺上添加快捷方式有兩種:一種桌面的快捷方式,一種是launcher的快捷方式。原理:是通過intent封裝一些信息,以Broadcast的形式通知launcher創建快捷方式的!一定不要忘記在manifest.xml中注冊一下權限

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT">

在manifest.xml中加入一個動作過濾的intentFilter,快捷方式的列表中會多個該程序的快捷方式。

有問題或向說點什么的可以留言,歡迎大家批評和指正,轉載請標明出處:

下面看一下程序的截圖:??

????????????????????????? ?? 程序的開始界面:?????????????????????????????????????點擊“將此程序添加快捷方式”按鈕:

???????????????????????????????????????????????? ? ??

?????????點擊退出按鈕,桌面多了快捷方式,彈Toast:????????????點出選擇快捷方式后多了程序的快捷方式:

????????????????????? ?????????????????????????? ??????

在IntentWidget工程中:

一、在com.cn.daming包中IntentWidgetMainActivity.java中的代碼:

[java]?view plaincopyprint?
  • <span><span>???
  • </span></span><span?style="font-size:13px;color:#000000;">package?com.cn.daming;??
  • ??
  • 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;??
  • import?android.widget.Toast;??
  • ??
  • public?class?IntentWidgetMainActivity?extends?Activity?implements?OnClickListener{??
  • ??
  • ????private?Button?mStartWidgetButton;??
  • ????private?Button?mExitButton;??
  • ??????
  • ????@Override??
  • ????public?void?onCreate(Bundle?savedInstanceState)?{??
  • ????????super.onCreate(savedInstanceState);??
  • ????????setContentView(R.layout.main);??
  • ????????mStartWidgetButton?=?(Button)?findViewById(R.id.my_button_1);??
  • ????????mExitButton?=?(Button)?findViewById(R.id.my_button_2);??
  • ????????mStartWidgetButton.setOnClickListener(this);??
  • ????????mExitButton.setOnClickListener(this);??
  • ????}??
  • ??????
  • ????public?void?onClick(View?v)??
  • ????{??
  • ????????if(v?==?mStartWidgetButton){??
  • ????????????//inint?the?widgetIntent?is?declear??
  • ????????????Intent?addWidgetIntent?=?new?Intent("com.android.launcher.action.INSTALL_SHORTCUT");??
  • ?????????????????????<span?style="white-space:?pre-wrap;"></span>//whether?repeat?create?is?or?not???
  • ?????????????????????addWdgetIntent.putExtra("duplicate",true);<span?style="font-family:?monospace;font-size:10px;"><span?style="white-space:?pre-wrap;"><span><span>??
  • </span></span></span></span>??
  • ????????????//set?the?Widget?of?the?title??
  • ????????????String?mTitle?=?getResources().getString(R.string.my_title);??
  • ????????????//set?the?Widget?of?the?icon??
  • ????????????Parcelable?icon?=?Intent.ShortcutIconResource.fromContext(this,?R.drawable.widget_image);??
  • ??????????????
  • ????????????Intent?mIntent?=?new?Intent(this,IntentWidgetMainActivity.class);??
  • ????????????addWidgetIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,?mTitle);//set?the?title??
  • ????????????addWidgetIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,?icon);//set?the?icon??
  • ????????????addWidgetIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,?mIntent);//set?the?intent??
  • ????????????sendBroadcast(addWidgetIntent);??
  • ????????}??
  • ????????else?if(v?==?mExitButton){??
  • ????????????finish();??
  • ????????????Toast.makeText(IntentWidgetMainActivity.this,?R.string.exit,?Toast.LENGTH_SHORT).show();??
  • ????????}??
  • ????}??
  • }</span>??
  • 二、在layout目錄下的main.xml中的代碼:

    [html]?view plaincopyprint?
  • <?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="fill_parent"??
  • ????android:background="#00ffffff"??
  • ????>??
  • ????<TextView????
  • ????????android:layout_width="fill_parent"???
  • ????????android:layout_height="wrap_content"???
  • ????????android:layout_marginTop="15dip"??
  • ????????android:layout_marginBottom="15dip"??
  • ????????android:gravity="center"??
  • ????????android:text="@string/hello"??
  • ????????android:textSize="8pt"??
  • ????????/>??
  • ????<Button??
  • ????????android:id="@+id/my_button_1"??
  • ????????android:layout_width="fill_parent"??
  • ????????android:layout_height="wrap_content"??
  • ????????android:layout_marginBottom="10dip"??
  • ????????android:textSize="10pt"??
  • ????????android:text="@string/my_button_1"??
  • ????/>??
  • ????<Button??
  • ????????android:id="@+id/my_button_2"??
  • ????????android:layout_width="fill_parent"??
  • ????????android:layout_height="wrap_content"??
  • ????????android:layout_marginBottom="10dip"??
  • ????????android:textSize="10pt"??
  • ????????android:text="@string/my_button_2"??
  • ????/>??
  • ????<TextView????
  • ????????android:layout_width="fill_parent"???
  • ????????android:layout_height="wrap_content"???
  • ????????android:layout_marginBottom="15dip"??
  • ????????android:gravity="center"??
  • ????????android:text="@string/blogs"??
  • ????????android:textSize="8pt"??
  • ????????/>??
  • </LinearLayout>??
  • 三、在values下的string.xml中的代碼:

    [html]?view plaincopyprint?
  • <?xml?version="1.0"?encoding="utf-8"?>??
  • <resources>??
  • ????<string?name="hello">這是大明添加到Launcher的快捷方式</string>??
  • ????<string?name="app_name">大明快捷方式!</string>??
  • ????<string?name="my_button_1">將此程序添加快捷方式</string>??
  • ????<string?name="my_button_2">退出程序</string>??
  • ????<string?name="my_title">大明程序</string>??
  • ????<string?name="exit">程序正在退出。。。。。。</string>??
  • ????<string?name="blogs">博客地址:\n?http://blog.csdn.net/wdaming1986/article/details/6877154</string>??
  • </resources>??
  • ?

    四、manifest.xml?中的代碼

    [html]?view plaincopyprint?
  • <?xml?version="1.0"?encoding="utf-8"?>??
  • <manifest?xmlns:android="http://schemas.android.com/apk/res/android"??
  • ??????package="com.cn.daming"??
  • ??????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=".IntentWidgetMainActivity"??
  • ??????????????????android:label="@string/app_name">??
  • ????????????<intent-filter>??
  • ????????????????<action?android:name="android.intent.action.MAIN"?/>??
  • ????????????????<category?android:name="android.intent.category.LAUNCHER"?/>??
  • ????????????</intent-filter>??
  • ????????????<!--?add?the?launch?of?my?programmer`s?quick?launcher-->??
  • ????????????<intent-filter>??
  • ????????????????<action?android:name="android.intent.action.CREATE_SHORTCUT"/>??
  • ????????????</intent-filter>??
  • ????????</activity>??
  • ????</application>??
  • ????<uses-permission?android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>??
  • </manifest>??
  • 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的Android中程序向桌面和Launcher添加快捷方式的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 中文字幕第99页 | 久久国产精品电影 | 国产成人免费电影 | 国产综合婷婷 | av无线看| 欧美精品一区二区久久婷婷 | 欧美熟妇久久久久 | 国产swag在线观看 | 亚洲4438| 日本激情一区 | 精品国产99久久久久久 | 人人综合 | 亚洲欧美亚洲 | 美女扒开腿让男人 | 卡一卡二在线视频 | 午夜xxx | 日韩超碰在线 | av激情网站 | 精品国产午夜 | 国产一级特黄aaa大片 | 2020国产精品 | 99视频网站| 天天爽天天爱 | 性生活毛片 | 久久久久人妻一区精品色欧美 | 99re这里只有精品在线观看 | www天堂在线 | 亚洲无码精品一区二区三区 | 国产一级片网址 | 国产麻豆电影在线观看 | 午夜xx| 性久久久久久久久久久 | 在线观看免费黄视频 | 婷婷色基地 | 欧美久久久久久久久久久 | 欧美毛片视频 | 国产123在线 | 中文字幕日本一区二区 | 天天色天天射综合网 | 狠狠艹av | 亚洲人女屁股眼交6 | av操操| 美女扒开让男人桶爽 | 日韩乱码人妻无码系列中文字幕 | 日本黄色小说 | 黄色在线视频网站 | 绿帽在线 | 国产亚洲综合精品 | 无码av天堂一区二区三区 | 激情久久av一区av二区av三区 | 少妇精品久久久一区二区三区 | 亚欧色视频| 国产成人午夜 | 日本少妇ⅹxxxxx视频 | 久久综合伊人 | 日韩av在线看 | 超碰av在线播放 | 国产a黄| 在线观看免费高清视频 | 中文字幕精 | www.青青操| 哈利波特3在线观看免费版英文版 | 九九这里只有精品视频 | 自拍av在线 | 影音先锋美女 | 国产精品v欧美精品v日韩 | 交hdsexvideos娇小| 欧美熟妇交换久久久久久分类 | 爱爱一级 | 欧美色图3p | 国产人妻久久精品一区二区三区 | 精品人妻无码一区二区性色 | 国产精品久久久久久久久久辛辛 | 亚洲自拍图片 | 亚洲情网 | 免费在线色视频 | 少妇被爽到高潮动态图 | 黄视频免费在线观看 | 91中文字日产乱幕4区 | 国产区在线看 | 91福利视频免费观看 | 一区二区www| 日韩欧美中文字幕一区 | 丁香花婷婷 | 精品视频日韩 | 色av网站| 麻豆一区二区三区四区 | 草草在线影院 | 女人被男人躁得好爽免费视频 | 天堂视频免费 | 中国一级黄色 | 久久亚洲aⅴ无码精品 | 久久精品性爱视频 | 色欲国产精品一区二区 | 在线观看99 | 91亚洲精品国偷拍自产在线观看 | 国产精品99无码一区二区视频 | 四虎影视黄色 | 影音先锋男人的天堂 |