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

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

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

2019-11-09 14:46:41
字體:
供稿:網(wǎng)友

原理:

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

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

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

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

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

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

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

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

權(quán)限

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

這個(gè)方法一般放在引導(dǎo)頁面

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快捷方式的細(xì)節(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è)置快捷方式的圖標(biāo) Intent value = new Intent(this,SplashActivity.class); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, value);//設(shè)置快捷方式的操作 sendBroadcast(intent); //如果創(chuàng)建了快捷方式,保存一個(gè)標(biāo)示,表示快捷方式創(chuàng)建 SharedPreferencesTool.saveBoolean(this, Constants.SHORTCUT, true); } }

或者 用標(biāo)簽進(jìn)行注冊(cè)

<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ù)庫(kù)的方法

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

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/應(yīng)用程序包名/cache //getFilesDir():data/data/應(yīng)用程序包名/files out = new FileOutputStream(file); //3.讀寫操作,實(shí)現(xiàn)拷貝 byte[] b = new byte[1024];//緩存區(qū)域 int len = -1;//保存讀取長(zhǎng)度 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(); } } } } }
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 图木舒克市| 桃园县| 罗源县| 右玉县| 合水县| 嵊州市| 蕲春县| 莎车县| 陆良县| 绥棱县| 叶城县| 公主岭市| 丽江市| 邹城市| 长海县| 江永县| 云南省| 托克托县| 广元市| 离岛区| 峨边| 正定县| 南陵县| 扬中市| 平和县| 赣榆县| 宣恩县| 商丘市| 襄城县| 新兴县| 孝昌县| 将乐县| 宝坻区| 兴宁市| 锦州市| 黎城县| 准格尔旗| 张家口市| 竹溪县| 全南县| 新沂市|