日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Android -- App生成快捷方式

發布時間:2025/3/17 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android -- App生成快捷方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉自:http://shaotao.blog.51cto.com/7606729/1332258
123456789101112131415161718192021222324252627282930313233343536373839404142434445publicclassMainActivity extendsActivity {@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//只第一次運行時生成,以后就不生成了SharedPreferences preferences = getSharedPreferences("isfrist_file",Context.MODE_PRIVATE);booleanisFirst = preferences.getBoolean("isfrist", true);if(isFirst) {//創建快捷方式createDeskShortCut();}SharedPreferences.Editor editor = preferences.edit();editor.putBoolean("isfrist", false);editor.commit();}publicvoidcreateDeskShortCut() {// 創建快捷方式的IntentIntent shortcut = newIntent("com.android.launcher.action.INSTALL_SHORTCUT");// 不允許重復創建shortcut.putExtra("duplicate", false);// 需要現實的名稱shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name));// 快捷圖片Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式入口Intent intent = newIntent(getApplicationContext(), MainActivity.class);// 下面兩個屬性是為了當應用程序卸載時,刪除桌面上的快捷方式intent.setAction("android.intent.action.MAIN");intent.addCategory("android.intent.category.LAUNCHER");// 點擊快捷圖片,運行的程序主入口shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// 發送廣播 OKsendBroadcast(shortcut);}}


還要添加創建快捷方式權限

1<uses-permissionandroid:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>



本文出自 “天馬行空” 博客,請務必保留此出處http://shaotao.blog.51cto.com/7606729/1332258


轉載于:https://blog.51cto.com/5841121/1340206

總結

以上是生活随笔為你收集整理的Android -- App生成快捷方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。