Android -- App生成快捷方式
生活随笔
收集整理的這篇文章主要介紹了
Android -- App生成快捷方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉自:http://shaotao.blog.51cto.com/7606729/1332258
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 | publicclassMainActivity 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生成快捷方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [032] 微信公众帐号开发教程第8篇-
- 下一篇: ajaxFileUpload plugi