-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNewActivity.kt
49 lines (41 loc) · 1.47 KB
/
NewActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.arindam.kotlin.shortcuts
import android.content.pm.ShortcutManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.arindam.kotlin.R
/**
* Created by Arindam Karmakar on 7/8/19.
*/
class NewActivity : AppCompatActivity() {
private val TAG by lazy { NewActivity::class.java.simpleName }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
manageShortcuts()
} else {
Log.e(TAG, "Build SDK must greater or equal Nougat (N_MR1)")
}
}
@RequiresApi(Build.VERSION_CODES.N_MR1)
private fun manageShortcuts() {
val shortcutManager = getSystemService(ShortcutManager::class.java)
shortcutManager?.let {
if (it.dynamicShortcuts.size == 0) {
// Application restored. Need to re-publish dynamic shortcuts.
if (it.pinnedShortcuts.size > 0) {
// Pinned shortcuts have been restored. Use
// updateShortcuts() to make sure they contain
// up-to-date information.
} else {
// Do something
}
} else {
Log.e(TAG, "${it.pinnedShortcuts}")
}
}
}
}