Updated on 2026-08-14
This commit is contained in:
parent
782e909ebd
commit
d71ee3f4d5
8 changed files with 213 additions and 234 deletions
52
app/src/main/java/com/tangem/util/CommonUtil.java
Normal file
52
app/src/main/java/com/tangem/util/CommonUtil.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package com.tangem.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
public static void sendEmail(Context context, File zipFile, String logTag, String subject, String text, File[] fileLocations) {
|
||||
if (zipFile != null) return;
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND)
|
||||
//.setData(new Uri.Builder().scheme("mailto").build())
|
||||
.setType("text/plain")
|
||||
.putExtra(Intent.EXTRA_EMAIL, new String[]{"android@tangem.com"})
|
||||
.putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
.putExtra(Intent.EXTRA_TEXT, text);
|
||||
|
||||
if (fileLocations != null && fileLocations.length > 0) {
|
||||
String[] fileNames = new String[fileLocations.length];
|
||||
for (int i = 0; i < fileLocations.length; i++)
|
||||
fileNames[i] = fileLocations[i].getAbsolutePath();
|
||||
zipFile = File.createTempFile("tangemLogs", ".zip", fileLocations[0].getParentFile());
|
||||
Compress compress = new Compress(fileNames, zipFile.getAbsolutePath());
|
||||
compress.zip();
|
||||
Log.e(logTag, String.format("Send %d bytes zip with logs", zipFile.length()));
|
||||
Uri attachment = Uri.parse("content://" + context.getString(R.string.log_file_provider_authorities) + "/" + zipFile.getName());
|
||||
|
||||
intent.putExtra(Intent.EXTRA_STREAM, attachment);
|
||||
zipFile.deleteOnExit();
|
||||
}
|
||||
|
||||
List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0);
|
||||
boolean isIntentSafe = activities.size() > 0;
|
||||
|
||||
if (isIntentSafe) {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
51
app/src/main/java/com/tangem/util/Compress.java
Normal file
51
app/src/main/java/com/tangem/util/Compress.java
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package com.tangem.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class Compress {
|
||||
private static final int BUFFER = 2048;
|
||||
|
||||
private String[] _files;
|
||||
private String _zipFile;
|
||||
|
||||
public Compress(String[] files, String zipFile) {
|
||||
_files = files;
|
||||
_zipFile = zipFile;
|
||||
}
|
||||
|
||||
public void zip() {
|
||||
try {
|
||||
BufferedInputStream origin = null;
|
||||
FileOutputStream dest = new FileOutputStream(_zipFile);
|
||||
|
||||
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
|
||||
|
||||
byte data[] = new byte[BUFFER];
|
||||
|
||||
for (String _file : _files) {
|
||||
Log.v("Compress", "Adding: " + _file);
|
||||
FileInputStream fi = new FileInputStream(_file);
|
||||
origin = new BufferedInputStream(fi, BUFFER);
|
||||
ZipEntry entry = new ZipEntry(_file.substring(_file.lastIndexOf("/") + 1));
|
||||
out.putNextEntry(entry);
|
||||
int count;
|
||||
while ((count = origin.read(data, 0, BUFFER)) != -1) {
|
||||
out.write(data, 0, count);
|
||||
}
|
||||
origin.close();
|
||||
}
|
||||
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue