当前位置: 首页 > news >正文

昆明网站建设猫咪科技抚州网站建设

昆明网站建设猫咪科技,抚州网站建设,移动端网站建设公司,酷炫 网站模板android某个功能和应用快捷方式 最近接受到一个任务#xff0c;给应用内的一个功能点创建一个快捷方式#xff0c;方便用户操作快捷、 一#xff0c;第一种方式#xff0c;只适用Build.VERSION.SDK_INT25 以上的版本 /** shortcutId 快捷方式的标示#xff0c;自己定…android某个功能和应用快捷方式 最近接受到一个任务给应用内的一个功能点创建一个快捷方式方便用户操作快捷、 一第一种方式只适用Build.VERSION.SDK_INT25 以上的版本 /** shortcutId 快捷方式的标示自己定义 * 固定快捷方式* Build.VERSION.SDK_INT25以上*/private fun createQuestPinShortcut(context: Context) {if (Build.VERSION.SDK_INT Build.VERSION_CODES.N_MR1) {if (mShortcutManager null) {mShortcutManager context.getSystemService(ShortcutManager::class.java)}var isExit falsemShortcutManager?.pinnedShortcuts?.forEach {if (shortcutId it.id) {//判断快捷方式是否已存在isExit trueToast.showToast(context, 快捷方式已存在)returnforEach}}if (mShortcutManager?.isRequestPinShortcutSupported true !isExit) {val intent Intent(context, ShortcutAlarmCallActivity::class.java)intent.action shortcutActionintent.action Intent.ACTION_VIEWval pinShortcutInfo ShortcutInfo.Builder(context, shortcutId).setShortLabel(context.getString(R.string.shortcut_alarm_long)).setLongLabel(context.getString(R.string.shortcut_alarm_long)).setIcon(Icon.createWithResource(context, R.mipmap.icon_alarm_emergency)).setIntent(intent).build()// 注册固定快捷方式成功广播val intentFilter IntentFilter()intentFilter.addAction(shortcutBroadcast)val receiver ShoutCutReceiver()context.registerReceiver(receiver, intentFilter)val flag PendingIntent.FLAG_IMMUTABLE or FLAG_UPDATE_CURRENTval pinnedShortcutCallbackIntent Intent(shortcutBroadcast)val successCallback PendingIntent.getBroadcast(context,0,pinnedShortcutCallbackIntent,flag)mShortcutManager?.requestPinShortcut(pinShortcutInfo, successCallback.intentSender)}}}二、第二种方式 适配android 8以下的版本和以上的版本 /*** 兼容创建快捷方式* param context Context*/open fun addShortCutCompact(context: Context) {if (isShortCutExist(context, context.getString(R.string.shortcut_alarm_long))) {Toast.showToast(context, 快捷方式已存在)return}if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {Toast.showToast(context, 无法创建快捷方式)return}val shortcutInfoIntent Intent()shortcutInfoIntent.setClassName(context, className)shortcutInfoIntent.action Intent.ACTION_VIEW //action必须设置不然报错val info ShortcutInfoCompat.Builder(context, shortcutId).setIcon(IconCompat.createWithResource(context, R.mipmap.icon_alarm_emergency)).setShortLabel(context.getString(R.string.shortcut_alarm_long)).setIntent(shortcutInfoIntent).build()// 注册固定快捷方式成功广播val intentFilter IntentFilter()intentFilter.addAction(shortcutBroadcast)val receiver ShoutCutReceiver()context.registerReceiver(receiver, intentFilter)val pinnedShortcutCallbackIntent Intent(shortcutBroadcast)val flag PendingIntent.FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT//当添加快捷方式的确认弹框弹出来时将被回调val shortcutCallbackIntent PendingIntent.getBroadcast(context,0,pinnedShortcutCallbackIntent,if (Build.VERSION.SDK_INT Build.VERSION_CODES.S) flag else 0)ShortcutManagerCompat.requestPinShortcut(context,info,null)}三、用第二种方式可以用以下方法判断是否存在快捷方式 /*** 判断是否存在快捷方式* param context Context* return Boolean*/private fun isShortCutExist(context: Context, title: String): Boolean {var isInstallShortcut falseif (TextUtils.isEmpty(title)) {return false}val contentResolver: ContentResolver context.contentResolvertry {val authority com.android.launcher3.settingsval url content://$authority/favorites?notifytrueval contentUrl: Uri Uri.parse(url)val strArray arrayOf(title, iconResource)val cursor: Cursor? contentResolver.query(contentUrl, strArray, title?,arrayOf(title.trim()), null)cursor?.let {if (it.count 0) {isInstallShortcut true}if (!it.isClosed) {it.close()}}} catch (e: Exception) {e.toString()}return isInstallShortcut}****## 最近要记得添加权限****kotlin!-- 添加快捷方式 --uses-permission android:namecom.android.launcher.permission.INSTALL_SHORTCUT /!-- 移除快捷方式 --uses-permission android:namecom.android.launcher.permission.UNINSTALL_SHORTCUT /!-- 查询快捷方式4.4以上 --uses-permission android:namecom.android.launcher3.permission.READ_SETTINGS /uses-permission android:namecom.android.launcher3.permission.WRITE_SETTINGS /如果要添加创建成功提示 class ShoutCutReceiver: BroadcastReceiver() {override fun onReceive(context: Context, intent: Intent) {Log.i(ShoutCutReceiver, onReceive: 创建成功)Toast.showToast(context, R.drawable.icon_succes_tip,创建成功)} }
http://www.zqtcl.cn/news/606570/

相关文章:

  • 怎么把自己的网站放到百度上九亭做网站
  • 张家界旅游网站建设网页设计作品欣赏分析
  • 订阅号自定义可以做链接网站不做网站dreamwa
  • 电子商务网站规划的原则做网站的集群方案
  • 山东建设银行怎么招聘网站自己做商城网站
  • 建设网站成本预算网站页面设计尺寸
  • 微官网和微网站首页房产网怎么查到房产
  • 高端服装产品网站建设织梦网站识别
  • 做调像什么网站找活注册网站请签署意见是写无
  • 郑州公司网站设计深圳福田有哪些公司
  • 怎么看网站是谁做的asp企业网站开发技术
  • 传奇手游网站大全9377编辑器wordpress
  • 网站集约化建设意见和建议苏州建设交通招聘信息网站
  • 网站建设优化的技巧衣服定制的app有哪些
  • 营销型网站建设报价vue本地访问服务器跨域
  • 支持api网站开发大疆网站建设
  • 国家排污许可网站台账怎么做进销存永久免费
  • 做游戏脚本的网站精品国内网站建设
  • 好的网站建站公司门户网站栏目维护建设方案
  • 如何在电脑上建立网站企业百度网站怎么做的
  • 34线城市做网站推广网站页面如何设计图
  • 成都网站建设前十广州开发网站设计
  • qq人脸解冻自助网站加工平台推荐
  • 中国室内设计联盟网官网网站专题页优化
  • 设计模板图热狗网站关键词优化
  • 无锡网站开发公司重庆网站有哪些
  • 做网站找什么公司工作网站开发思维导图内容
  • 有人知道做网站吗?wordpress多站点cdn
  • 网站风格特点大型外包公司有哪些
  • 如何网站seo用asp做网站有哪控件