Skip to content

Commit 799dfa7

Browse files
authored
Merge pull request #478 from jasonz1987/develop
2.5.0
2 parents c8da4c7 + fd3affb commit 799dfa7

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 2.5.0 - 2018-12-26
4+
### Fixed
5+
- Android preferences code problem
6+
37
## 2.4.0 - 2018-07-27
48
### Added
59
- Android compress thumb

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
**如果是使用cordova7以上版本,请切换到develop-cordova7分支代码。**
44

5+
QQ群:190808518
6+
57
# cordova-plugin-wechat
68

79
A cordova plugin, a JS version of Wechat SDK

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-wechat",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "A cordova plugin, a JS version of Wechat SDK",
55
"cordova": {
66
"id": "cordova-plugin-wechat",

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:rim="http://www.blackberry.com/ns/widgets"
55
xmlns:android="http://schemas.android.com/apk/res/android"
66
id="cordova-plugin-wechat"
7-
version="2.4.0">
7+
version="2.5.0">
88

99
<name>Wechat</name>
1010
<description>A cordova plugin, a JS version of Wechat SDK</description>

src/android/EntryActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public void onResp(BaseResp resp) {
101101
}
102102

103103
// restore appid
104-
final String appid = Wechat.getAppId();
104+
final String appid = Wechat.getAppId(null);
105105
final String savedAppId = Wechat.getSavedAppId(this);
106106
if (!savedAppId.equals(appid)) {
107-
Wechat.saveAppId(this, Wechat.getAppId());
107+
Wechat.saveAppId(this, Wechat.getAppId(null));
108108
}
109109

110110
finish();

src/android/Wechat.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.InputStream;
4242
import java.io.ByteArrayOutputStream;
4343
import java.io.ByteArrayInputStream;
44+
import org.apache.cordova.CordovaPreferences;
4445

4546
public class Wechat extends CordovaPlugin {
4647

@@ -98,13 +99,14 @@ public class Wechat extends CordovaPlugin {
9899
protected static CallbackContext currentCallbackContext;
99100
protected static IWXAPI wxAPI;
100101
protected static String appId;
102+
protected static CordovaPreferences wx_preferences;
101103

102104
@Override
103105
protected void pluginInitialize() {
104106

105107
super.pluginInitialize();
106108

107-
String id = getAppId();
109+
String id = getAppId(preferences);
108110

109111
// save app id
110112
saveAppId(cordova.getActivity(), id);
@@ -117,9 +119,11 @@ protected void pluginInitialize() {
117119

118120
protected void initWXAPI() {
119121
IWXAPI api = getWxAPI(cordova.getActivity());
120-
122+
if(wx_preferences == null) {
123+
wx_preferences = preferences;
124+
}
121125
if (api != null) {
122-
api.registerApp(getAppId());
126+
api.registerApp(getAppId(preferences));
123127
}
124128
}
125129

@@ -280,7 +284,7 @@ protected boolean sendPaymentRequest(CordovaArgs args, CallbackContext callbackC
280284

281285
try {
282286
final String appid = params.getString("appid");
283-
final String savedAppid = getAppId(cordova.getActivity());
287+
final String savedAppid = getSavedAppId(cordova.getActivity());
284288
if (!savedAppid.equals(appid)) {
285289
this.saveAppId(cordova.getActivity(), appid);
286290
}
@@ -332,7 +336,7 @@ protected boolean chooseInvoiceFromWX(CordovaArgs args, CallbackContext callback
332336
ChooseCardFromWXCardPackage.Req req = new ChooseCardFromWXCardPackage.Req();
333337

334338
try {
335-
req.appId = getAppId();
339+
req.appId = getAppId(preferences);
336340
req.cardType = "INVOICE";
337341
req.signType = params.getString("signType");
338342
req.cardSign = params.getString("cardSign");
@@ -541,10 +545,7 @@ protected Bitmap getBitmap(JSONObject message, String key, int maxSize) {
541545

542546
/**
543547
* compress bitmap by quility
544-
*
545-
* @param url
546-
* @return
547-
*/
548+
*/
548549
protected Bitmap compressImage(Bitmap image,Integer maxSize) {
549550

550551
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -563,9 +564,6 @@ protected Bitmap compressImage(Bitmap image,Integer maxSize) {
563564

564565
/**
565566
* Get input stream from a url
566-
*
567-
* @param url
568-
* @return
569567
*/
570568
protected InputStream getFileInputStream(String url) {
571569
try {
@@ -626,9 +624,13 @@ protected InputStream getFileInputStream(String url) {
626624
return null;
627625
}
628626

629-
public static String getAppId() {
627+
public static String getAppId(CordovaPreferences f_preferences) {
630628
if (appId == null) {
631-
appId = preferences.getString(WXAPPID_PROPERTY_KEY, "");
629+
if(f_preferences != null) {
630+
appId = f_preferences.getString(WXAPPID_PROPERTY_KEY, "");
631+
}else if(wx_preferences != null){
632+
appId = wx_preferences.getString(WXAPPID_PROPERTY_KEY, "");
633+
}
632634
}
633635

634636
return appId;
@@ -650,7 +652,7 @@ public static String getSavedAppId(Context ctx) {
650652
* @param id
651653
*/
652654
public static void saveAppId(Context ctx, String id) {
653-
if (id.isEmpty()) {
655+
if (id!=null && id.isEmpty()) {
654656
return ;
655657
}
656658

0 commit comments

Comments
 (0)