- vừa được xem lúc

Dynamic Shortcuts Android

0 0 19

Người đăng: Phương Trần

Theo Viblo Asia

Chào mọi người, đây là first post của mình =)))

Trong bài này mình sẽ giới thiệu cho các bạn 1 thứ rất hay ho : Dynamic Shortcuts Android

Ok bắt đầu.


class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Shortcut Manager để quản lý shortcuts var shortcutManager = getSystemService(ShortcutManager::class.java) // Tạo Shortcut 1 var shortcut1 = ShortcutInfo.Builder(applicationContext, "ID1") //id .setShortLabel("Instagram") // lable hiển thị .setLongLabel("Long lablelllll") //long lable, không nhất thiết phải set .setIcon(Icon.createWithResource(applicationContext, R.drawable.icon))// icon hiển thị .setIntent(Intent(Intent.ACTION_VIEW, Uri.parse("https://www.instagram.com"))) //intent khi action vào .setRank(xxx) // set rank nếu có nhiều shortcuts và cần ưu tiên .build() // add shortcut vào list, có thể add max 4 shortcuts shortcutManager!!.dynamicShortcuts = listOf(shortcut1) //tới đây thì khi run class lên, bạn đã tạo thành công shortcut rồi đấy // Update shortcuts , mình sẽ lấy ví dụ là 1 action click btnUpdate.setOnClickListener { shortcut1 = ShortcutInfo.Builder(applicationContext, "ID1") .setShortLabel("Google") .setIcon(Icon.createWithResource(applicationContext, R.drawable.icon)) .setIntent(Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com"))) .build() //update lại tất cả thông tin, nhưng vẫn giữ ID nhé, shortcutManager!!.dynamicShortcuts = listOf(shortcut1) } // Add thêm shortcut btnAdd.setOnClickListener { var shortcut2 = ShortcutInfo.Builder(applicationContext, "ID2") .setShortLabel("Newly Appended") .setIcon(Icon.createWithResource(applicationContext, R.drawable.icon)) .setIntent(Intent(Intent.ACTION_VIEW, Uri.parse("https://www.newlyAppended.com"))) .build() shortcutManager!!.dynamicShortcuts = listOf(shortcut1, shortcut2) } //Remove shortcuts btnRemove.setOnClickListener { shortcutManager.removeAllDynamicShortcuts() } }
} 

Chúc các bạn thành công.

Thanks

Bình luận

Bài viết tương tự

- vừa được xem lúc

Học Flutter từ cơ bản đến nâng cao. Phần 1: Làm quen cô nàng Flutter

Lời mở đầu. Gần đây, Flutter nổi lên và được Google PR như một xu thế của lập trình di động vậy.

0 0 254

- vừa được xem lúc

Học Flutter từ cơ bản đến nâng cao. Phần 3: Lột trần cô nàng Flutter, BuildContext là gì?

Lời mở đầu. Màn làm quen cô nàng FLutter ở Phần 1 đã gieo rắc vào đầu chúng ta quá nhiều điều bí ẩn về nàng Flutter.

0 0 189

- vừa được xem lúc

[Android] Hiển thị Activity trên màn hình khóa - Show Activity over lock screen

Xin chào các bạn, Hôm nay là 30 tết rồi, ngồi ngắm trời chờ đón giao thừa, trong lúc rảnh rỗi mình quyết định ngồi viết bài sau 1 thời gian vắng bóng. .

0 0 93

- vừa được xem lúc

Tìm hiểu Proguard trong Android

1. Proguard là gì . Cụ thể nó giúp ứng dụng của chúng ta:. .

0 0 83

- vừa được xem lúc

Làm ứng dụng học toán đơn giản với React Native - Phần 6

Chào các bạn một năm mới an khang thịnh vượng, dồi dào sức khỏe. Lại là mình đây Đây là link app mà các bạn đang theo dõi :3 https://play.google.com/store/apps/details?id=com.

0 0 51

- vừa được xem lúc

20 Plugin hữu ích cho Android Studio

1. CodeGlance. Plugin này sẽ nhúng một minimap vào editor cùng với thanh cuộn cũng khá là lớn. Nó sẽ giúp chúng ta xem trước bộ khung của code và cho phép điều hướng đến đoạn code mà ta mong muốn một cách nhanh chóng.

0 0 301