imporved updating

This commit is contained in:
2021-04-02 21:06:15 +02:00
parent 90dc2bb9eb
commit e3dc1a161b
4 changed files with 74 additions and 24 deletions
+15 -3
View File
@@ -5,9 +5,12 @@
<package android:name="us.zoom.videomeetings" />
</queries>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<application
android:allowBackup="true"
@@ -28,5 +31,14 @@
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
</application>
</manifest>
@@ -3,8 +3,11 @@ package de.joel.zoomhelper;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
@@ -23,6 +26,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
@@ -34,6 +38,7 @@ import com.google.android.material.textfield.TextInputLayout;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -135,7 +140,6 @@ public class MainActivity extends AppCompatActivity {
watchShareIcon();
watchShortcutIcon();
watchTestDLIcon();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
@@ -149,26 +153,32 @@ public class MainActivity extends AppCompatActivity {
launchZoomUrl(url);
} else {
AppUpdater appUpdater = new AppUpdater(this).setUpdateFrom(UpdateFrom.XML).setUpdateXML("https://baldaufwd.de/ZoomHelper/update.xml");
appUpdater.setButtonUpdateClickListener((dialog, which) -> downloadAPK());
appUpdater.start();
}
}
private void watchTestDLIcon() {
Button testDLBtn = findViewById(R.id.btnTestDL);
testDLBtn.setOnClickListener(v -> {
downloadAPK();
});
}
private void downloadAPK() {
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
String fileName = "ZoomHelper.apk";
destination += fileName;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// this will request for permission when user has not granted permission for the app
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
} else {
//Delete update file if exists
File file = new File(destination);
final Uri localUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file);
if (file.exists())
//file.delete() - test this, I think sometimes it doesnt work
file.delete();
//Download Script
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("https://baldaufwd.de/ZoomHelper/ZoomHelper.apk");
@@ -176,10 +186,34 @@ public class MainActivity extends AppCompatActivity {
request.setVisibleInDownloadsUi(true);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment());
downloadManager.enqueue(request);
final long downloadID = downloadManager.enqueue(request);
BroadcastReceiver onDownloadComplete = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Fetching the download id received with the broadcast
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
//Checking if the received broadcast is for our enqueued download by matching download id
if (downloadID == id) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
install.setDataAndType(localUri,
downloadManager.getMimeTypeForDownloadedFile(downloadID));
startActivity(install);
unregisterReceiver(this);
}
}
};
registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
}
private void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
String meetingID = "";
+3 -11
View File
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="wrap_content">
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
@@ -23,13 +24,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/btnSave" />
<Button
android:id="@+id/btnTestDL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:onClick="btnJoin_onClick"
android:text="testDL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/btnSave" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<files-path
name="files"
path="." />
</paths>