国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

APP實用開發(fā)—桌面添加快捷圖標

2019-11-09 15:54:03
字體:
供稿:網(wǎng)友

原理:

這里寫圖片描述 從圖上可以看出,Android大致分7步完成快捷方式的創(chuàng)建:

**第1步:**Android系統(tǒng)的launcher程序會調(diào)用它的pickShortcut()方法去啟動系統(tǒng)的pickActivity程序(應用);

**第2步:**pickActivity程序(應用)啟動后會調(diào)用它的CheckIntentFilter()方法,去在系統(tǒng)中尋找可以創(chuàng)建快捷方式的應用有哪些,并且列舉出來。只要第三方 App用標簽進行了相應的注冊(具體如何注冊請看下面的代碼)就可以被發(fā)現(xiàn)并列舉出來;

第3步:調(diào)用Choseitem()方法選擇創(chuàng)建誰的快捷方式;

第4步:完成第三步之后,pickActivity程序(應用)會將選擇的消息通過Intent返回給系統(tǒng)的launcher;

**第5步:**launcher程序獲得pickActivity返回的消息后,就會知道創(chuàng)建誰的快捷方式,通過調(diào)用PRocessShortcut()方法去啟動第三方App中負責創(chuàng)建快捷方式 的Activity,這個Activity就是第二步中我們提到的用標簽進行了注冊的Activity;

第6步:第三方App中負責創(chuàng)建快捷方式的Activity會將快捷方式的名稱,圖標和點擊后跳轉(zhuǎn)路徑通過Intent返回給launcher;

**第7部:**launcher收到返回的消息后調(diào)用本身的ComPleteAddShortcut()方法完成快捷方式的創(chuàng)建,并顯示在桌面上;

權(quán)限

<!-- 添加快捷方式 --> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

這個方法一般放在引導頁面

private void createShortCut() { boolean b = SharedPreferencesTool.getBoolean(this, Constants.SHORTCUT, false); if (!b) { Intent intent = new Intent(); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //通過intent告訴launcher快捷方式的細節(jié) intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "淘寶");//設(shè)置快捷方式的名稱 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);//設(shè)置快捷方式的圖標 Intent value = new Intent(this,SplashActivity.class); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, value);//設(shè)置快捷方式的操作 sendBroadcast(intent); //如果創(chuàng)建了快捷方式,保存一個標示,表示快捷方式創(chuàng)建 SharedPreferencesTool.saveBoolean(this, Constants.SHORTCUT, true); } }

或者 用標簽進行注冊

<activity android:name=".CreatShortCut"> <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT"/> </intent-filter></activity>

向Launcher返回相關(guān)數(shù)據(jù)

public class CreatShortCut extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) { Intent _returnIntent = new Intent(); _returnIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "csx");// 快捷鍵的名字 _returnIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,// 快捷鍵的ico Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher)); _returnIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, MainActivity.class));// 快捷鍵的跳轉(zhuǎn)Intent setResult(RESULT_OK, _returnIntent);// 發(fā)送 finish();// 關(guān)閉本Activity } }}

拷貝數(shù)據(jù)庫的方法

引用外置的數(shù)據(jù)庫,在引導頁面初始化

private void copyDb(String fileName) { File file = new File(getFilesDir(), fileName); if (!file.exists()) { //1.獲取assets目錄的管理者 assets = getAssets(); InputStream in = null; FileOutputStream out = null; try { //2.讀取資源 in = assets.open(fileName);//打開assets目錄的資源,fileName:資源的名稱 //getCacheDir():data/data/應用程序包名/cache //getFilesDir():data/data/應用程序包名/files out = new FileOutputStream(file); //3.讀寫操作,實現(xiàn)拷貝 byte[] b = new byte[1024];//緩存區(qū)域 int len = -1;//保存讀取長度 while((len = in.read(b)) != -1){ out.write(b, 0, len); } } catch (IOException e) { e.printStackTrace(); }finally{ //關(guān)流操作 if (out != null) { try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
上一篇:Swift 隱式可選型

下一篇:Button和TextView

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临沂市| 龙南县| 建平县| 湖口县| 富民县| 红河县| 海丰县| 阿勒泰市| 子洲县| 百色市| 蓬溪县| 普兰县| 安泽县| 申扎县| 内江市| 公安县| 颍上县| 秀山| 聂荣县| 承德县| 南昌市| 通州区| 双城市| 灵川县| 桑日县| 丰原市| 怀安县| 临夏市| 多伦县| 方山县| 个旧市| 永德县| 巨野县| 丹阳市| 阿坝| 凤城市| 万宁市| 洪江市| 城口县| 高清| 和硕县|