Commit eed0620b authored by wanglei's avatar wanglei

...

parent aefcca9a
......@@ -20,6 +20,8 @@ import com.base.browserwhite.ui.fragment.HomeFragment
import com.base.browserwhite.ui.views.DialogViews.showDefaultBrowserDialog
import com.base.browserwhite.ui.views.DialogViews.showMyAccountDialog
import com.base.browserwhite.utils.BarUtils
import com.base.browserwhite.utils.LogEx
import com.base.browserwhite.utils.ShortcutUtils.createShortcut
import java.io.File
class MainActivity : BaseActivity<ActivityMainBinding>() {
......@@ -92,6 +94,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.llMy.setOnClickListener {
showMyAccountDialog()
}
try {
createShortcut()
} catch (e: Exception) {
LogEx.logDebug(TAG, "")
}
}
......
package com.base.browserwhite.utils
import android.content.Context
import android.content.Intent
import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.os.Build
import com.base.browserwhite.R
import com.base.browserwhite.ui.activity.splash.Splash2Activity
object ShortcutUtils {
fun Context.createShortcut() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val shortcutManager = getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
shortcutManager.isRequestPinShortcutSupported
val shortcutInfo = ShortcutInfo.Builder(this, "shortcut_id")
.setShortLabel("快捷方式标题")
.setLongLabel("快捷方式的详细描述")
.setIcon(Icon.createWithResource(this, R.mipmap.logo))
.setIntent(Intent(this, Splash2Activity::class.java).apply {
// 设置Intent的额外信息,例如:
// putExtra("EXTRA_KEY", "extra_value")
// 设置标志,避免在启动Activity时重新启动
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
.build()
shortcutManager.addDynamicShortcuts(listOf(shortcutInfo))
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment