-
Notifications
You must be signed in to change notification settings - Fork 35
/
IntentExtActivity.kt
75 lines (63 loc) · 1.99 KB
/
IntentExtActivity.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package luyao.util.ktx.ui
import android.Manifest
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.files.FileFilter
import com.afollestad.materialdialogs.files.fileChooser
import luyao.util.ktx.bean.ItemBean
import luyao.util.ktx.ext.*
import luyao.util.ktx.ext.permission.request
/**
* Created by luyao
* on 2019/6/18 10:48
*/
class IntentExtActivity : CommonListActivity() {
override fun getToolbarTitle() = "IntentExt"
override fun initList() {
dataList.run {
add(ItemBean("App Info", null))
add(ItemBean("Date And Timezone", null))
add(ItemBean("Language And Input", null))
add(ItemBean("Accessibility Setting", null))
add(ItemBean("Install Apk", null))
add(ItemBean("Uninstall Apk", null))
add(ItemBean("Open in store", null))
add(ItemBean("Open Browser", null))
}
}
override fun handleClick(position: Int) {
when (position) {
0 -> goToAppInfoPage()
1 -> goToDateAndTimePage()
2 -> goToLanguagePage()
3 -> goToAccessibilitySetting()
4 -> installApk()
5 -> uninstallApp(packageName)
6 -> openInAppStore(packageName)
7 -> openBrowser("https://www.baidu.com")
}
}
private fun installApk() {
request(Manifest.permission.READ_EXTERNAL_STORAGE) {
onGranted {
chooseFile()
}
onDenied {
toast("onDenied")
}
onShowRationale {
toast("onShowRationale")
}
onNeverAskAgain {
toast("onNeverAskAgain")
}
}
}
private fun chooseFile() {
val apkFilter: FileFilter = { it.name.endsWith(".apk") }
MaterialDialog(this).show {
fileChooser(filter = apkFilter) { _, file ->
installApk(file)
}
}
}
}