4
4
import android .content .Context ;
5
5
import android .content .Intent ;
6
6
import android .content .IntentFilter ;
7
- import android .text .TextUtils ;
8
-
9
- import androidx .annotation .NonNull ;
10
-
11
- import java .util .List ;
12
- import java .util .Map ;
13
7
14
8
/**
15
9
* Author : MJ
@@ -36,7 +30,7 @@ public class AndroidKeyWatcher {
36
30
* @param context context
37
31
* @param iKeyWatcher 监听器
38
32
*/
39
- public void register (@ NonNull Context context , IKeyWatcher iKeyWatcher ) {
33
+ public void register (Context context , IKeyWatcher iKeyWatcher ) {
40
34
this .iKeyWatcher = iKeyWatcher ;
41
35
registerReceiver (context );
42
36
}
@@ -46,7 +40,7 @@ public void register(@NonNull Context context, IKeyWatcher iKeyWatcher) {
46
40
*
47
41
* @param context context
48
42
*/
49
- public void unRegister (@ NonNull Context context ) {
43
+ public void unRegister (Context context ) {
50
44
this .iKeyWatcher = null ;
51
45
unRegisterReceiver (context );
52
46
}
@@ -56,19 +50,19 @@ public void unRegister(@NonNull Context context) {
56
50
*
57
51
* @param context context
58
52
*/
59
- private void registerReceiver (@ NonNull Context context ) {
53
+ private void registerReceiver (Context context ) {
60
54
if (keyReceiver == null ) {
61
55
keyReceiver = new KeyReceiver ();
62
56
}
63
57
// 使用applicationContext,是为了防止activity的内存泄漏
64
- if (context .getApplicationContext () != null ) {
58
+ if (context != null && context .getApplicationContext () != null ) {
65
59
IntentFilter filter = new IntentFilter (Intent .ACTION_CLOSE_SYSTEM_DIALOGS );
66
60
context .getApplicationContext ().registerReceiver (keyReceiver , filter );
67
61
}
68
62
}
69
63
70
- private void unRegisterReceiver (@ NonNull Context context ) {
71
- if (context .getApplicationContext () != null && keyReceiver != null ) {
64
+ private void unRegisterReceiver (Context context ) {
65
+ if (context != null && context .getApplicationContext () != null && keyReceiver != null ) {
72
66
context .getApplicationContext ().unregisterReceiver (keyReceiver );
73
67
}
74
68
}
0 commit comments