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

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

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

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

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

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

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

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

下面模擬在應(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); //獲取快捷鍵的圖標
   Intent myIntent=new Intent(this, ShortCutAction.class);
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");//快捷方式的標題
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//快捷方式的圖標
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);//快捷方式的動作
   sendBroadcast(addIntent);//發(fā)送廣播
   break;
  case R.id.exit:
   System.exit(0);
   break;
  }
 }
}

運行結(jié)果:

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

相關(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)知識,他們的基本使用方法,在文中都給大家提到,具體內(nèi)容詳情大家通過本文一起學(xué)習吧
    2017-12-12
  • Android仿制淘寶滾動圖文條的示例代碼

    Android仿制淘寶滾動圖文條的示例代碼

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

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

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

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

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

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

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

    Android自定義動態(tài)壁紙開發(fā)(時鐘)

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

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

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

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

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

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

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

    android讀取assets中Excel表格并顯示

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

最新評論