网站做的一样算侵权吗,站群建站系统,个人网站 怎么设计,网站搭建系统都有哪些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,创建成功)}
}