|
@ -3,6 +3,9 @@ package com.electric.chargingpile.wxapi;
|
3
|
3
|
|
4
|
4
|
import android.app.Activity;
|
5
|
5
|
import android.content.Intent;
|
|
6
|
import android.content.pm.ActivityInfo;
|
|
7
|
import android.content.res.TypedArray;
|
|
8
|
import android.os.Build;
|
6
|
9
|
import android.os.Bundle;
|
7
|
10
|
import android.util.Log;
|
8
|
11
|
import android.widget.Toast;
|
|
@ -14,6 +17,9 @@ import com.tencent.mm.sdk.openapi.IWXAPI;
|
14
|
17
|
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
|
15
|
18
|
import com.tencent.mm.sdk.openapi.WXAPIFactory;
|
16
|
19
|
|
|
20
|
import java.lang.reflect.Field;
|
|
21
|
import java.lang.reflect.Method;
|
|
22
|
|
17
|
23
|
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
|
18
|
24
|
|
19
|
25
|
private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
|
|
@ -23,6 +29,10 @@ public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
|
23
|
29
|
|
24
|
30
|
@Override
|
25
|
31
|
public void onCreate(Bundle savedInstanceState) {
|
|
32
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
|
|
33
|
boolean result = fixOrientation();
|
|
34
|
Log.i(TAG,"onCreate fixOrientation when Oreo, result = " + result);
|
|
35
|
}
|
26
|
36
|
super.onCreate(savedInstanceState);
|
27
|
37
|
setContentView(R.layout.pay_result);
|
28
|
38
|
|
|
@ -30,6 +40,45 @@ public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
|
30
|
40
|
api.handleIntent(getIntent(), this);
|
31
|
41
|
}
|
32
|
42
|
|
|
43
|
private boolean isTranslucentOrFloating() {
|
|
44
|
boolean isTranslucentOrFloating = false;
|
|
45
|
try {
|
|
46
|
int [] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);
|
|
47
|
final TypedArray ta = obtainStyledAttributes(styleableRes);
|
|
48
|
Method m = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class);
|
|
49
|
m.setAccessible(true);
|
|
50
|
isTranslucentOrFloating = (boolean)m.invoke(null, ta);
|
|
51
|
m.setAccessible(false);
|
|
52
|
} catch (Exception e) {
|
|
53
|
e.printStackTrace();
|
|
54
|
}
|
|
55
|
return isTranslucentOrFloating;
|
|
56
|
}
|
|
57
|
// 修复8.0微信支付问题
|
|
58
|
// https://blog.csdn.net/starry_eve/article/details/82777160
|
|
59
|
private boolean fixOrientation() {
|
|
60
|
try {
|
|
61
|
Field field = Activity.class.getDeclaredField("mActivityInfo");
|
|
62
|
field.setAccessible(true);
|
|
63
|
ActivityInfo o = (ActivityInfo)field.get(this);
|
|
64
|
o.screenOrientation = -1;
|
|
65
|
field.setAccessible(false);
|
|
66
|
return true;
|
|
67
|
}catch (Exception e) {
|
|
68
|
e.printStackTrace();
|
|
69
|
}
|
|
70
|
return false;
|
|
71
|
}
|
|
72
|
|
|
73
|
@Override
|
|
74
|
public void setRequestedOrientation(int requestedOrientation) {
|
|
75
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
|
|
76
|
Log.i(TAG, "avoid calling setRequestedOrientation when Oreo.");
|
|
77
|
return;
|
|
78
|
}
|
|
79
|
super.setRequestedOrientation(requestedOrientation);
|
|
80
|
}
|
|
81
|
|
33
|
82
|
@Override
|
34
|
83
|
protected void onNewIntent(Intent intent) {
|
35
|
84
|
super.onNewIntent(intent);
|