Mia's Home


  • 首页

  • 归档

  • 关于

NotificationUtils.kt

发表于 2018-07-25 | 分类于 android
字数统计: 360 | 阅读时长 ≈ 2

用于App是否打开通知选项,并且可跳转至相关Setting页面进行设置

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
76
77
import android.app.AppOpsManager
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import java.lang.reflect.InvocationTargetException

// NotificationUtils is a class that could judge notification status or not ,
// and could enableNotification
object NotificationUtils {

private const val CHECK_OP_NO_THROW = "checkOpNoThrow"
private const val OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION"

@JvmStatic
fun enableNotification(context: Context) =
Intent().apply {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
//android 8.0引导
action = "android.settings.APP_NOTIFICATION_SETTINGS"
putExtra("android.provider.extra.APP_PACKAGE", context.packageName)
}
Build.VERSION.SDK_INT in Build.VERSION_CODES.LOLLIPOP..Build.VERSION_CODES.N_MR1 -> {
//android 5.0-7.0
action = "android.settings.APP_NOTIFICATION_SETTINGS"
putExtra("app_package", context.packageName)
putExtra("app_uid", context.applicationInfo.uid)
}
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP -> {
action = "android.settings.APPLICATION_DETAILS_SETTINGS"
data = Uri.fromParts("package", context.packageName, null)
}
}
}

@JvmStatic
fun areNotificationsEnabled(context: Context) = with(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
areNotificationsEnabled()
} else {
isNotificationEnabled(context)
}
}

private fun isNotificationEnabled(context: Context): Boolean {

val mAppOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
val appInfo = context.applicationInfo
val pkg = context.applicationContext.packageName
val uid = appInfo.uid

val appOpsClass: Class<*>? /* Context.APP_OPS_MANAGER */

try {
appOpsClass = Class.forName(AppOpsManager::class.java.name)
val checkOpNoThrowMethod = appOpsClass!!.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String::class.java)
val opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION)
val value = opPostNotificationValue.get(Int::class.java) as Int

return checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) as Int == AppOpsManager.MODE_ALLOWED
} catch (e: ClassNotFoundException) {
e.printStackTrace()
} catch (e: NoSuchMethodException) {
e.printStackTrace()
} catch (e: NoSuchFieldException) {
e.printStackTrace()
} catch (e: InvocationTargetException) {
e.printStackTrace()
} catch (e: IllegalAccessException) {
e.printStackTrace()
}

return false
}
}

ScreenLogger了解一下

发表于 2018-07-24 | 分类于 Android
字数统计: 160 | 阅读时长 ≈ 1

ScreenLogger – 一个简单可用的屏幕日志插件

How to Use it?

  1. Add it in your root build.gradle at the end of repositories:
1
2
3
4
5
6
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Add the dependency

1
2
3
dependencies {
implementation 'com.github.BestDI:ScreenLogger:v1.0'
}

阅读全文 »

Android Log工具类

发表于 2018-05-04 | 分类于 Android
字数统计: 1,094 | 阅读时长 ≈ 7

MainLog.java,使用方法为 private MainLog LOG = new MainLog(clazz)
Download Jar

阅读全文 »

Android KeyStore使用,公钥,私钥签名

发表于 2018-04-25 | 分类于 Android
字数统计: 581 | 阅读时长 ≈ 3

Android KeyStore的使用,可以生成公钥和使用私钥签名:

相比较与Java的RSA生成的方式,使用Android KeyStore会更加安全。
具体的使用可以参加如下Java类:

阅读全文 »

Android Fingerprint浅析

发表于 2018-04-21 | 分类于 Android
字数统计: 2,217 | 阅读时长 ≈ 10

一,Fingerprint总体架构图

Fingerprint表层模块架构如下,只涉及Application,Framework,Frigerprintd以及FingerprintHal,不包含指纹的认证驱动;

Fp_communication

阅读全文 »

源码理解SharedPrefences

发表于 2018-04-21
字数统计: 3,556 | 阅读时长 ≈ 16

一、前言

SharedPreferences会从shared_prefs目录下的<name>.xml文件, 并将其以get/put的形式提供读写服务. 其中涉及到如下几个问题:

  1. 如何从磁盘读取配置到内存
  2. getXxx如何从内存中获取配置
  3. 最终配置如何从内存回写到磁盘
  4. 多线程/多进程是否会有问题
  5. 以及最佳实践
阅读全文 »

Vysor Pro破解

发表于 2018-04-14 | 分类于 tools
字数统计: 169 | 阅读时长 ≈ 1

Vysor Pro破解

下载官网 Vysor

文中在WIN10环境下针对chrome插件版本的Vysor进行的破解

阅读全文 »

AndFix原理及源码解析

发表于 2018-04-01 | 分类于 Android , 三方框架
字数统计: 1,989 | 阅读时长 ≈ 10

一、概述

AndFix 是阿里系的一个轻量级热修复,热更新框架,只支持简单的method修改,没有res修复等臃肿功能。具体的实现是通过native进行原函数的指针替换,具有一次修复,持续有效的特性(当然是不清除app所有数据前提下)。AndFix has a native method art_replaceMethod in ART or dalvik_replaceMethod in Dalvik.

方法替换原理

阅读全文 »

EventBus 源码赏析

发表于 2018-03-29 | 分类于 Android , 三方框架
字数统计: 2,828 | 阅读时长 ≈ 12

一 、简单概括

  • EventBus是一个Android/Java平台基于订阅与发布的同通信框架,不支持跨进程。可以用于Activity/Fragment/Thread/Service之间通信解耦,也可以用于多线程通信。
  • EventBus相对于BroadcastReceiver、Handler、接口回调的有点在于简单,事件的订阅和发布解耦,但是存在的问题也很明显,会有大量的Event类来管理
  • Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.
  • GITHUB直连
阅读全文 »
12
Mia

Mia

live like a dog~

19 日志
10 分类
8 标签
GitHub E-Mail
© 2018 人生是一种不可阻挡的进步
Hosted by GitHub
0%