亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android O添加桌面快捷方式的示例

 更新時間:2018年01月16日 08:31:53   作者:Maxiye  
本篇文章主要介紹了AndroidO添加桌面快捷方式的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

手機升級到安卓O后,突然發(fā)現(xiàn)創(chuàng)建快捷方式的功能失效了,查詢一番后發(fā)現(xiàn):安卓O要使用ShortcutManager來創(chuàng)建快捷方式。

安卓N及以下版本:

Intent addShortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//"com.android.launcher.action.INSTALL_SHORTCUT"
// 不允許重復(fù)創(chuàng)建
addShortcutIntent.putExtra("duplicate", false);// 經(jīng)測試不是根據(jù)快捷方式的名字判斷重復(fù)的
// 應(yīng)該是根據(jù)快鏈的Intent來判斷是否重復(fù)的,即Intent.EXTRA_SHORTCUT_INTENT字段的value
// 但是名稱不同時,雖然有的手機系統(tǒng)會顯示Toast提示重復(fù),仍然會建立快鏈
// 屏幕上沒有空間時會提示
// 注意:重復(fù)創(chuàng)建的行為MIUI和三星手機上不太一樣,小米上似乎不能重復(fù)創(chuàng)建快捷方式

// 名字
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "網(wǎng)絡(luò)設(shè)置");
// 圖標
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
  Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_perm_data_setting_black_24dp));

// 設(shè)置關(guān)聯(lián)程序
Intent launcherIntent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);//設(shè)置網(wǎng)絡(luò)頁面intent
// 設(shè)置關(guān)聯(lián)程序
// Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
// launcherIntent.setClass(MainActivity.this, MainActivity.class);
// launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);

// 發(fā)送廣播
sendBroadcast(addShortcutIntent);

安卓O:

ShortcutManager scm = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
Intent launcherIntent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);//設(shè)置網(wǎng)絡(luò)頁面intent
ShortcutInfo si = new ShortcutInfo.Builder(this, "dataroam")
  .setIcon(Icon.createWithResource(this, R.drawable.ic_perm_data_setting_black_24dp))
  .setShortLabel("網(wǎng)絡(luò)設(shè)置")
  .setIntent(launcherIntent)
  .build();
assert scm != null;
scm.requestPinShortcut(si, null);

那如果要兩者兼顧呢,則可以如下這樣寫:

//添加快捷方式
private void addShortcut() {
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  ShortcutManager scm = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
  Intent launcherIntent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);//設(shè)置網(wǎng)絡(luò)頁面intent
  ShortcutInfo si = new ShortcutInfo.Builder(this, "dataroam")
    .setIcon(Icon.createWithResource(this, R.drawable.ic_perm_data_setting_black_24dp))
    .setShortLabel("網(wǎng)絡(luò)設(shè)置")
    .setIntent(launcherIntent)
    .build();
  assert scm != null;
  scm.requestPinShortcut(si, null);
 } else {
  Intent addShortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//"com.android.launcher.action.INSTALL_SHORTCUT"
  // 不允許重復(fù)創(chuàng)建
  addShortcutIntent.putExtra("duplicate", false);// 經(jīng)測試不是根據(jù)快捷方式的名字判斷重復(fù)的
  // 應(yīng)該是根據(jù)快鏈的Intent來判斷是否重復(fù)的,即Intent.EXTRA_SHORTCUT_INTENT字段的value
  // 但是名稱不同時,雖然有的手機系統(tǒng)會顯示Toast提示重復(fù),仍然會建立快鏈
  // 屏幕上沒有空間時會提示
  // 注意:重復(fù)創(chuàng)建的行為MIUI和三星手機上不太一樣,小米上似乎不能重復(fù)創(chuàng)建快捷方式

  // 名字
  addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "網(wǎng)絡(luò)設(shè)置");
  // 圖標
  addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_perm_data_setting_black_24dp));

  // 設(shè)置關(guān)聯(lián)程序
  Intent launcherIntent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);//設(shè)置網(wǎng)絡(luò)頁面intent
  // 設(shè)置關(guān)聯(lián)程序
//  Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
//  launcherIntent.setClass(MainActivity.this, MainActivity.class);
//  launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);

  // 發(fā)送廣播
  sendBroadcast(addShortcutIntent);
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android 的回調(diào)事件詳解

    Android 的回調(diào)事件詳解

    這篇文章主要介紹了Android 的回調(diào)事件的相關(guān)資料,相當(dāng)?shù)脑敿殻行枰男』锇榭梢詤⒖枷?/div> 2016-08-08
  • 詳解Android 藍牙通信方式總結(jié)

    詳解Android 藍牙通信方式總結(jié)

    這篇文章主要介紹了詳解Android 藍牙通信方式總結(jié),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2013-11-11
  • 如何在XML中定義菜單

    如何在XML中定義菜單

    這篇文章主要為大家詳細介紹了在XML中定義菜單的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Android中刪除文件以及文件夾的命令記錄

    Android中刪除文件以及文件夾的命令記錄

    這篇文章主要介紹了Android中刪除文件以及文件夾的命令,需要的朋友可以參考下
    2013-06-06
  • 詳解Android Handler的使用

    詳解Android Handler的使用

    這篇文章主要介紹了Android Handler使用的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-04-04
  • Android自定義單例AlertDialog詳解

    Android自定義單例AlertDialog詳解

    這篇文章主要為大家詳細介紹了Android自定義單例AlertDialog的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android實現(xiàn)將應(yīng)用崩潰信息發(fā)送給開發(fā)者并重啟應(yīng)用的方法

    Android實現(xiàn)將應(yīng)用崩潰信息發(fā)送給開發(fā)者并重啟應(yīng)用的方法

    這篇文章主要介紹了Android實現(xiàn)將應(yīng)用崩潰信息發(fā)送給開發(fā)者并重啟應(yīng)用的方法,涉及Android錯誤處理與應(yīng)用操作的相關(guān)技巧,需要的朋友可以參考下
    2016-03-03
  • 淺析Android代碼質(zhì)量管理

    淺析Android代碼質(zhì)量管理

    本篇文章給大家分享了Android代碼質(zhì)量管理的相關(guān)知識點以及重點分析,對此有興趣的朋友可以參考學(xué)習(xí)下。
    2018-05-05
  • android編程實現(xiàn)電話錄音的方法

    android編程實現(xiàn)電話錄音的方法

    這篇文章主要介紹了android編程實現(xiàn)電話錄音的方法,涉及Android監(jiān)聽電話通話及音頻采集的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • Android開發(fā)登陸案例

    Android開發(fā)登陸案例

    這篇文章主要介紹了Android開發(fā)登陸案例的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07

最新評論