-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSystemDeviceUtil.java
More file actions
88 lines (67 loc) · 2.52 KB
/
SystemDeviceUtil.java
File metadata and controls
88 lines (67 loc) · 2.52 KB
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
78
79
80
81
82
83
84
85
86
87
88
package com.hht.uc.Quicksetting.utils;
import android.content.Context;
import java.lang.reflect.Method;
import android.media.AudioManager;
public class SystemDeviceUtil {
public static void setMute(boolean mute,AudioManager audiomanger){
Class<?> c = null;
try {
c = Class.forName("android.media.AudioManager");
Method m1 = c.getMethod("setMasterMute", boolean.class);
m1.invoke(audiomanger,mute);
} catch (Exception e){
e.printStackTrace();
}
}
// public static void setMute(boolean mute,Context context){
// Class<?> c = null;
// AudioManager mAudioManager = null;
// try {
// c = Class.forName("android.media.AudioManager");
//
// java.lang.reflect.Constructor<?> con = c.getConstructor(Context.class);
//
// mAudioManager = (AudioManager) con.newInstance(context);
//
// Method m1 = c.getMethod("setMasterMute", boolean.class);
//
// m1.invoke(mAudioManager,mute);
// } catch (Exception e){
// e.printStackTrace();
// }
//
// }
public static void setWifiP2pDeviceName(String devName,Context context) {
WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
WifiP2pManager.Channel channel = manager.initialize(context, context.getMainLooper(), null);
try {
Class[] paramTypes = new Class[3];
paramTypes[0] = WifiP2pManager.Channel.class;
paramTypes[1] = String.class;
paramTypes[2] = WifiP2pManager.ActionListener.class;
Method setDeviceName = manager.getClass().getMethod(
"setDeviceName", paramTypes);
setDeviceName.setAccessible(true);
Object arglist[] = new Object[3];
arglist[0] = channel;
arglist[1] = devName;
arglist[2] = new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
}
@Override
public void onFailure(int reason) {
}
};
setDeviceName.invoke(manager, arglist);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}