欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android通過應(yīng)用程序創(chuàng)建快捷方式的方法

 更新時(shí)間:2015年09月27日 12:51:59   作者:Ruthless  
這篇文章主要介紹了Android通過應(yīng)用程序創(chuàng)建快捷方式的方法,涉及Android基于應(yīng)用程序創(chuàng)建快捷方式的圖標(biāo)及動(dòng)作等技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android通過應(yīng)用程序創(chuàng)建快捷方式的方法。分享給大家供大家參考。具體如下:

Android 快捷方式是桌面最基本的組件。它用于直接啟動(dòng)某一應(yīng)用程序的某個(gè)組件。

一般情況下,可以在Launcher的應(yīng)用程序列表上,通過長(zhǎng)按某一個(gè)應(yīng)用程序的圖標(biāo)在左面上創(chuàng)建改該應(yīng)用程序的快捷方式。另外,還可以通過兩種方式在桌面上添加快捷方式:

一:在應(yīng)用程序中創(chuàng)建一個(gè)Intent,然后以Broadcast的形式通知Launcher創(chuàng)建一個(gè)快捷方式。

二:為應(yīng)用程序的組件注冊(cè)某一個(gè)符合特定條件的IntentFilter,然后可以直接在Launcher的桌面添加啟動(dòng)該組件的快捷方式。

下面模擬在應(yīng)用程序中添加快捷方式

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="fill_parent">
 <Button android:id="@+id/createShortcut"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:textSize="20px"
  android:text="創(chuàng)建快捷鍵"/>
 <Button android:id="@+id/exit"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:textSize="20px"
  android:text="退出"/>
</LinearLayout>

清單文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.ljq.action" android:versionCode="1"
 android:versionName="1.0">
 <application android:icon="@drawable/icon"
  android:label="@string/app_name">
  <activity android:name=".ShortCutAction"
   android:label="@string/app_name">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category
     android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
 </application>
 <uses-sdk android:minSdkVersion="7" />
 <!-- 添加快捷鍵權(quán)限 -->
 <uses-permission
  android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
</manifest>

ShortCutAction類:

package com.ljq.action;
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;
/**
 * 通過應(yīng)用程序創(chuàng)建快捷方式
 * 
 * @author jiqinlin
 *
 */
public class ShortCutAction extends Activity implements OnClickListener{
 private Button createShortcut=null; //創(chuàng)建快捷鍵按鈕
 private Button exit=null;//退出系統(tǒng)
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  createShortcut=(Button)findViewById(R.id.createShortcut);
  exit=(Button)findViewById(R.id.exit);
  createShortcut.setOnClickListener(this);
  exit.setOnClickListener(this);
 }
 public void onClick(View v) {
  //Button btn=(Button)v;
  switch (v.getId()) {
  case R.id.createShortcut:
   //String title=getResources().getString(R.string.title);
   Intent addIntent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   Parcelable icon=Intent.ShortcutIconResource.fromContext(this, R.drawable.png); //獲取快捷鍵的圖標(biāo)
   Intent myIntent=new Intent(this, ShortCutAction.class);
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");//快捷方式的標(biāo)題
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//快捷方式的圖標(biāo)
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);//快捷方式的動(dòng)作
   sendBroadcast(addIntent);//發(fā)送廣播
   break;
  case R.id.exit:
   System.exit(0);
   break;
  }
 }
}

運(yùn)行結(jié)果:

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 淺析AndroidStudio3.0最新 Android Profiler分析器(cpu memory network 分析器)

    淺析AndroidStudio3.0最新 Android Profiler分析器(cpu memory network

    Android Profiler分為三大模塊: cpu、內(nèi)存 、網(wǎng)絡(luò)。本文給大家介紹AndroidStudio3.0最新 Android Profiler分析器(cpu memory network 分析器)的相關(guān)知識(shí),他們的基本使用方法,在文中都給大家提到,具體內(nèi)容詳情大家通過本文一起學(xué)習(xí)吧
    2017-12-12
  • Android仿制淘寶滾動(dòng)圖文條的示例代碼

    Android仿制淘寶滾動(dòng)圖文條的示例代碼

    這篇文章主要介紹了Android仿制淘寶滾動(dòng)圖文條的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2018-08-08
  • Android開發(fā)中LayoutInflater用法詳解

    Android開發(fā)中LayoutInflater用法詳解

    這篇文章主要介紹了Android開發(fā)中LayoutInflater用法,結(jié)合實(shí)例形式分析了LayoutInflater類的功能、作用、使用方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-08-08
  • Android中用Builder模式自定義Dialog的方法

    Android中用Builder模式自定義Dialog的方法

    在任何軟件操作系統(tǒng)中,Dialog即對(duì)話框都是一種重要的交互模式與信息載體,而Android系統(tǒng)本身的Dialog擁有固定的樣式,并且在5.0后采用Material Design設(shè)計(jì)風(fēng)格的Dialog美觀大氣。這篇文章將詳細(xì)介紹Android中用Builder模式自定義Dialog的方法,有需要的可以參考借鑒。
    2016-10-10
  • Android 處理 View 重復(fù)點(diǎn)擊的多種方法

    Android 處理 View 重復(fù)點(diǎn)擊的多種方法

    這篇文章主要介紹了Android 處理 View 重復(fù)點(diǎn)擊的多種方法,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-03-03
  • Android自定義動(dòng)態(tài)壁紙開發(fā)(時(shí)鐘)

    Android自定義動(dòng)態(tài)壁紙開發(fā)(時(shí)鐘)

    今天小編就為大家分享一篇關(guān)于Android自定義動(dòng)態(tài)壁紙開發(fā)(時(shí)鐘),小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-01-01
  • ListView的Adapter使用(綁定數(shù)據(jù)) 之 自定義每一項(xiàng)的布局去綁定數(shù)據(jù)

    ListView的Adapter使用(綁定數(shù)據(jù)) 之 自定義每一項(xiàng)的布局去綁定數(shù)據(jù)

    之前寫的綁定數(shù)據(jù)是只是簡(jiǎn)單的綁定了字符串,這次我們將一次綁定多條數(shù)據(jù)并且嘗試用自定義的布局。在這篇文章中首先講解的是用Hashmap 去綁定數(shù)據(jù),第二個(gè)例子,講解自定義布局然后綁定數(shù)據(jù)
    2013-06-06
  • Android實(shí)戰(zhàn)教程第四十篇之Chronometer實(shí)現(xiàn)倒計(jì)時(shí)

    Android實(shí)戰(zhàn)教程第四十篇之Chronometer實(shí)現(xiàn)倒計(jì)時(shí)

    這篇文章主要介紹了Android實(shí)戰(zhàn)教程第四十篇之Chronometer實(shí)現(xiàn)倒計(jì)時(shí),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • 使用IntelliJ IDEA 配置安卓(Android)開發(fā)環(huán)境的教程詳解(新手必看)

    使用IntelliJ IDEA 配置安卓(Android)開發(fā)環(huán)境的教程詳解(新手必看)

    這篇文章主要介紹了使用IntelliJ IDEA 配置安卓(Android)開發(fā)環(huán)境的教程詳解(新手必看),本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • android讀取assets中Excel表格并顯示

    android讀取assets中Excel表格并顯示

    這篇文章主要為大家詳細(xì)介紹了android讀取assets中Excel表格并顯示的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02

最新評(píng)論