1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
View.OnClickListener mButtonHandler =
new
View.OnClickListener() {
public
void
onClick(View v) {
Message m =
null
;
if
(v == mButtonPositive && mButtonPositiveMessage !=
null
) {
m = Message.obtain(mButtonPositiveMessage);
}
else
if
(v == mButtonNegative && mButtonNegativeMessage !=
null
) {
m = Message.obtain(mButtonNegativeMessage);
}
else
if
(v == mButtonNeutral && mButtonNeutralMessage !=
null
) {
m = Message.obtain(mButtonNeutralMessage);
}
if
(m !=
null
) {
m.sendToTarget();
}
// Post a message so we dismiss after the above handlers are executed
mHandler.obtainMessage(ButtonHandler.MSG_DISMISS_DIALOG, mDialogInterface)
.sendToTarget();
}
};
|
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
|
private
static
final
class
ButtonHandler
extends
Handler {
// Button clicks have Message.what as the BUTTON{1,2,3} constant
private
static
final
int
MSG_DISMISS_DIALOG =
1
;
private
WeakReference<DialogInterface> mDialog;
public
ButtonHandler(DialogInterface dialog) {
mDialog =
new
WeakReference<DialogInterface>(dialog);
}
@Override
public
void
handleMessage(Message msg) {
switch
(msg.what) {
case
DialogInterface.BUTTON_POSITIVE:
case
DialogInterface.BUTTON_NEGATIVE:
case
DialogInterface.BUTTON_NEUTRAL:
((DialogInterface.OnClickListener) msg.obj).onClick(mDialog.get(), msg.what);
break
;
case
MSG_DISMISS_DIALOG:
((DialogInterface) msg.obj).dismiss();
}
}
}
|
1
2
3
4
5
6
7
|
Field field = dialogBuilder.getClass().getDeclaredField(
"mAlert"
);
field.setAccessible(
true
);
Object obj = field.get(dialogBuilder);
field = obj.getClass().getDeclaredField(
"mHandler"
);
field.setAccessible(
true
);
field.set(obj,
new
ButtonHandler(dialogBuilder));
//设置我们自己定义的ButtonHandler
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Method method1 = wifi.getClass().getMethod(
"setWifiApEnabled"
,WifiConfiguration.
class
,
boolean
.
class
);
WifiConfiguration netConfig =
new
WifiConfiguration();
netConfig.SSID =
"\"Express Sensor\""
;
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
netConfig.preSharedKey =
"11111111"
;
method1.invoke(wifi, netConfig, enabled);
Method method2 = wifi.getClass().getMethod(
"getWifiApState"
);
state = (Integer) method2.invoke(wifi);
|