1
0
mirror of https://github.com/etesync/android synced 2025-05-22 00:38:48 +00:00

Debug info: send inline on Android <4.1 and when creating an attachment doesn't work

This commit is contained in:
Ricki Hirner 2016-10-22 02:05:14 +02:00
parent 08639b2e89
commit f2d5fe32c5

View File

@ -28,7 +28,6 @@ import android.text.TextUtils;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.WordUtils;
@ -86,23 +85,39 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage
sendIntent.setType("text/plain"); sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " debug info"); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " debug info");
try { // since Android 4.1, FileProvider permissions are handled in a useful way (using ClipData)
File debugInfoDir = new File(getCacheDir(), "debug-info"); boolean asAttachment = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
debugInfoDir.mkdir();
reportFile = new File(debugInfoDir, "debug.txt"); if (asAttachment)
App.log.fine("Writing debug info to " + reportFile.getAbsolutePath()); try {
FileWriter writer = new FileWriter(reportFile); File debugInfoDir = new File(getCacheDir(), "debug-info");
writer.write(report); debugInfoDir.mkdir();
writer.close();
sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, getString(R.string.authority_log_provider), reportFile)); reportFile = new File(debugInfoDir, "debug.txt");
App.log.fine("Writing debug info to " + reportFile.getAbsolutePath());
FileWriter writer = new FileWriter(reportFile);
writer.write(report);
writer.close();
startActivity(Intent.createChooser(sendIntent, null)); sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, getString(R.string.authority_log_provider), reportFile));
} catch (IOException e) { sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
App.log.log(Level.SEVERE, "Couldn't write debug info file", e);
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } catch(IOException e) {
} // creating an attachment failed, so send it inline
asAttachment = false;
StringBuilder builder = new StringBuilder();
builder .append("Couldn't write debug info file:\n")
.append(ExceptionUtils.getStackTrace(e))
.append("\n\n")
.append(report);
report = builder.toString();
}
if (!asAttachment)
sendIntent.putExtra(Intent.EXTRA_TEXT, report);
startActivity(Intent.createChooser(sendIntent, null));
} }
} }