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

pull/2/head
Ricki Hirner 8 years ago
parent 08639b2e89
commit f2d5fe32c5

@ -28,7 +28,6 @@ import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.text.WordUtils;
@ -86,6 +85,10 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " debug info");
// since Android 4.1, FileProvider permissions are handled in a useful way (using ClipData)
boolean asAttachment = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
if (asAttachment)
try {
File debugInfoDir = new File(getCacheDir(), "debug-info");
debugInfoDir.mkdir();
@ -97,12 +100,24 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage
writer.close();
sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, getString(R.string.authority_log_provider), reportFile));
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} 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));
} catch (IOException e) {
App.log.log(Level.SEVERE, "Couldn't write debug info file", e);
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}
}

Loading…
Cancel
Save