You've already forked RN_Android_VersionUpgrade
							
							用Handler
This commit is contained in:
		@@ -8,6 +8,8 @@ import android.content.pm.PackageInfo;
 | 
				
			|||||||
import android.content.pm.PackageManager;
 | 
					import android.content.pm.PackageManager;
 | 
				
			||||||
import android.net.Uri;
 | 
					import android.net.Uri;
 | 
				
			||||||
import android.os.Build;
 | 
					import android.os.Build;
 | 
				
			||||||
 | 
					import android.os.Handler;
 | 
				
			||||||
 | 
					import android.os.Message;
 | 
				
			||||||
import android.provider.Settings;
 | 
					import android.provider.Settings;
 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -65,7 +67,7 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void _alertDialog(){
 | 
					    void _alertDialog(){
 | 
				
			||||||
        final UpgradeModule that = this;
 | 
					        final UpgradeModule that = this;
 | 
				
			||||||
        AlertDialog dialog = new AlertDialog.Builder(reactContext.getCurrentActivity())
 | 
					        AlertDialog dialog = new AlertDialog.Builder(reactContext.getCurrentActivity())
 | 
				
			||||||
                .setTitle(TITLE)
 | 
					                .setTitle(TITLE)
 | 
				
			||||||
@@ -119,6 +121,7 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
 | 
				
			|||||||
                .method("GET", null)
 | 
					                .method("GET", null)
 | 
				
			||||||
                .build();
 | 
					                .build();
 | 
				
			||||||
        Call call = okHttpClient.newCall(request);
 | 
					        Call call = okHttpClient.newCall(request);
 | 
				
			||||||
 | 
					        final Handler handler = new ShowUpgradeAlertHandler(that);
 | 
				
			||||||
        call.enqueue(new Callback() {
 | 
					        call.enqueue(new Callback() {
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
            public void onFailure(Call call, IOException e) {
 | 
					            public void onFailure(Call call, IOException e) {
 | 
				
			||||||
@@ -134,12 +137,12 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
 | 
				
			|||||||
                        Log.d("VERSION CHECK", jsonText);
 | 
					                        Log.d("VERSION CHECK", jsonText);
 | 
				
			||||||
                        JSONObject json = new JSONObject(jsonText);
 | 
					                        JSONObject json = new JSONObject(jsonText);
 | 
				
			||||||
                        int status = json.getInt("status");
 | 
					                        int status = json.getInt("status");
 | 
				
			||||||
                        CONTENT = json.getString("message");
 | 
					 | 
				
			||||||
                        if(status > 0){
 | 
					                        if(status > 0){
 | 
				
			||||||
                            String version = json.getString("version");
 | 
					                            CONTENT = json.getString("message");
 | 
				
			||||||
 | 
					//                            String version = json.getString("version");
 | 
				
			||||||
                            JSONObject jsonData = json.getJSONObject("data");
 | 
					                            JSONObject jsonData = json.getJSONObject("data");
 | 
				
			||||||
                            DOWNLOAD_URL = jsonData.getString("url");
 | 
					                            DOWNLOAD_URL = jsonData.getString("url");
 | 
				
			||||||
                            that._alertDialog();
 | 
					                            handler.sendEmptyMessage(0);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } catch (IOException e) {
 | 
					                    } catch (IOException e) {
 | 
				
			||||||
                        Log.e("REQUEST FAILED", "AAA", e);
 | 
					                        Log.e("REQUEST FAILED", "AAA", e);
 | 
				
			||||||
@@ -151,3 +154,17 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					final class ShowUpgradeAlertHandler extends Handler
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private UpgradeModule module;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ShowUpgradeAlertHandler(UpgradeModule module)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        this.module = module;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void handleMessage(Message message){
 | 
				
			||||||
 | 
					        module._alertDialog();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user