mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
merge
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package com.capacitorjs.app.testapp;
|
||||
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
|
||||
public class MainActivity extends BridgeActivity {}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.gpr.gabinetedigital;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class App extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();
|
||||
|
||||
Map<String,Object> defaultValue = new HashMap<>();
|
||||
defaultValue.put(UpdateHelper.KEY_UPDATE_ENABLE,false);
|
||||
defaultValue.put(UpdateHelper.KEY_UPDATE_VERSION,"1.0");
|
||||
defaultValue.put(UpdateHelper.KEY_UPDATE_URL,"https://d953-41-63-166-54.ngrok.io/gabinete_digital.apk");
|
||||
|
||||
remoteConfig.setDefaults(defaultValue);
|
||||
remoteConfig.fetch(1)
|
||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if(task.isSuccessful()) {
|
||||
remoteConfig.activateFetched();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.gpr.gabinetedigital;
|
||||
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
|
||||
public class MainActivity extends BridgeActivity {}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.gpr.gabinetedigital;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Application;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class UpdateActivity extends Application implements UpdateHelper.onUpdateCheckListener {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
UpdateHelper.with(this)
|
||||
.onUpdateCheck(this)
|
||||
.check();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCheckListener(String urlApp) {
|
||||
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(this)
|
||||
.setTitle("New Version Available")
|
||||
.setMessage("Please update to new version to continue use")
|
||||
.setPositiveButton("UPDATE", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Toast.makeText(UpdateActivity.this, ""+urlApp,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}).setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}).create();
|
||||
alertDialog.show();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.gpr.gabinetedigital;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class UpdateApp extends AsyncTask<String,Void,Void> {
|
||||
private Context context;
|
||||
public void setContext(Context contextf){
|
||||
context = contextf;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... arg0) {
|
||||
try {
|
||||
URL url = new URL(arg0[0]);
|
||||
HttpURLConnection c = (HttpURLConnection) url.openConnection();
|
||||
c.setRequestMethod("GET");
|
||||
c.setDoOutput(true);
|
||||
c.connect();
|
||||
|
||||
String PATH = "/mnt/sdcard/Download/";
|
||||
File file = new File(PATH);
|
||||
file.mkdirs();
|
||||
File outputFile = new File(file, "update.apk");
|
||||
if(outputFile.exists()){
|
||||
outputFile.delete();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(outputFile);
|
||||
|
||||
InputStream is = c.getInputStream();
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int len1 = 0;
|
||||
while ((len1 = is.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, len1);
|
||||
}
|
||||
fos.close();
|
||||
is.close();
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/Download/update.apk")), "application/vnd.android.package-archive");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
|
||||
context.startActivity(intent);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("UpdateAPP", "Update error! " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.gpr.gabinetedigital;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
||||
|
||||
public class UpdateHelper {
|
||||
public static String KEY_UPDATE_ENABLE = "is_update";
|
||||
public static String KEY_UPDATE_VERSION = "version";
|
||||
public static String KEY_UPDATE_URL = "update_url";
|
||||
|
||||
public interface onUpdateCheckListener {
|
||||
void onUpdateCheckListener(String urlApp);
|
||||
}
|
||||
|
||||
public static Builder with(Context context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
private onUpdateCheckListener onUpdateCheckListener;
|
||||
private Context context;
|
||||
|
||||
public UpdateHelper(Context context, UpdateHelper.onUpdateCheckListener onUpdateCheckListener) {
|
||||
this.onUpdateCheckListener = onUpdateCheckListener;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void check() {
|
||||
FirebaseRemoteConfig remoteconfig = FirebaseRemoteConfig.getInstance();
|
||||
if(remoteconfig.getBoolean(KEY_UPDATE_ENABLE)) {
|
||||
String currentVersion = remoteconfig.getString(KEY_UPDATE_VERSION);
|
||||
String appVersion = getAppVersion(context);
|
||||
String updateURL = remoteconfig.getString(KEY_UPDATE_URL);
|
||||
|
||||
if(!TextUtils.equals(currentVersion,appVersion) && onUpdateCheckListener != null)
|
||||
onUpdateCheckListener.onUpdateCheckListener(updateURL);
|
||||
}
|
||||
}
|
||||
|
||||
private String getAppVersion(Context context) {
|
||||
String result ="";
|
||||
|
||||
try {
|
||||
result = context.getPackageManager().getPackageInfo(context.getPackageName(), 0)
|
||||
.versionName;
|
||||
result = result.replaceAll("[a-ZA-Z] |-", "");
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Context context;
|
||||
private onUpdateCheckListener onUpdateCheckListener;
|
||||
|
||||
public Builder(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder onUpdateCheck(onUpdateCheckListener onUpdateCheckListener) {
|
||||
this.onUpdateCheckListener = onUpdateCheckListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdateHelper build() {
|
||||
return new UpdateHelper(context, onUpdateCheckListener);
|
||||
}
|
||||
|
||||
public UpdateHelper check() {
|
||||
UpdateHelper updateHelper = build();
|
||||
updateHelper.check();
|
||||
|
||||
return updateHelper;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user