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

运城市网站建设_网站建设公司_网站备案_seo优化

个人网站 服务器,自适应营销网站模板,付费网站建设,软件技术专升本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.ihoyoo.com/news/64671.html

相关文章:

  • 合肥建站公司seo论文网站建设的参考文献
  • 网站对联图片国外网站会让国内人做吗
  • 做恐怖网站自己做视频网站能赚钱
  • 最适合seo的网站源码网站方案策划
  • 建个购物网站wordpress缩写是什么意思
  • 古风网站的关于我们页面怎么做python 网站开发 环境
  • 做儿童网站赚钱吗手机版wordpress使用
  • 保定网站建设公司免费网络营销公司哪家好
  • 外贸网站域名用境内还是境外上海建设资质审批网站
  • 怎么做交易猫钓鱼网站无锡网站推
  • 建一个国外网站多少钱网站搭建好了不用会不会被攻击
  • 公司网站可以自己做吗wordpress 整合ucenter
  • react做的电商网站能上线吗用vs2010做购物网站
  • php外贸网站制作信誉好的永州网站建设
  • 蜗牛星际做网站服务器集团网站策划方案
  • 购物网站大全免费微信分销系统
  • 网站建立时间怎么查电商小程序制作一个需要多少钱
  • 做仿网站公司电白网站开发公司
  • 工信部网站备案怎么查询专门做10s视频的网站
  • 蚌埠网站排名接做网站简介
  • 自助建站系统php做计算机项目的网站
  • 黄山建设厅官方网站wordpress登录后台不显示登录
  • 意大利室内设计网站石家庄英文网站建设
  • 长沙宁乡建设网站wordpress 优秀的博客主题简洁
  • 网站开发与程序开发网站开发与设计结课论文
  • 搜索网站内容高端定制网站的特点
  • 河南做网站企起河南工程
  • php免费网站源码江门公司网站建设
  • 手机视频网站设计自建论坛要多少钱
  • 手机网站导航页精品网课平台