zoukankan      html  css  js  c++  java
  • android如何添加桌面图标和卸载程序后自动删除图标

    android如何添加桌面图标和卸载程序后自动删除桌面图标,这是一个应用的安装与卸载过程对桌面图标的操作,下面与大家分享下具体是如何实现的,感兴趣的朋友可以参考下哈

    1:创建图标如下 

    Intent intent = new Intent(); 
    intent.setClass(this, SplashActivity.class); 
    Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT); 
    Parcelable icon = Intent.ShortcutIconResource.fromContext(this, 
    R.drawable.icon); 
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); 
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); 
    addShortcut.putExtra("duplicate", 0); 
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); 
    sendBroadcast(addShortcut); 

    2:删除图标如下 

    Intent intent = new Intent(); 
    intent.setClass(this, SplashActivity.class); 
    intent.setAction("android.intent.action.MAIN"); 
    intent.addCategory("android.intent.category.LAUNCHER"); 
    Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT); 
    Parcelable icon = Intent.ShortcutIconResource.fromContext(this, 
    R.drawable.icon); 
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); 
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); 
    addShortcut.putExtra("duplicate", 0); 
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); 
    sendBroadcast(addShortcut); 
    intent.setAction("android.intent.action.MAIN"); 
    intent.addCategory("android.intent.category.LAUNCHER"); 

    需要两个过滤属性

  • 相关阅读:
    android事件拦截处理机制详解
    序列化
    事件系统的一般性
    Android应用启动、退出分析
    Android Activity.startActivity流程简介
    ActivityThread
    Android Activity学习笔记——Activity的启动和创建
    attachBaseContext
    新认识的类
    深入理解Intent和IntentFiler(一)
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5204555.html
Copyright © 2011-2022 走看看