やあみんな私は基本的にエラーが発生したときにクラッシュレポートを電子メールで私に送信するためにいくつかのソースコードを構成するのに助けが必要です。これが私が遊んでいるコードです。Javaをもう少し経験した人がそれを見落とし、クリーンアップするのを手伝ってくれる必要があります。
ありがとう、
public final class EmailUtils {
private EmailUtils()
{
}
private static int bytesToMb(long l)
{
return (int)((double)l / 1024D / 1024D);
}
private static int getAvailableInternalMemorySize()
{
StatFs statfs = new StatFs(Environment.getDataDirectory().getPath());
return bytesToMb((long)statfs.getBlockSize() * (long)statfs.getAvailableBlocks());
}
private static String getEmailText(Context context)
{
String s = "";
String s11;
PackageInfo packageinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
String s1 = packageinfo.versionName;
int i = packageinfo.versionCode;
String s2 = packageinfo.packageName;
String s3 = Build.MODEL;
String s4 = android.os.Build.VERSION.RELEASE;
String s5 = android.os.Build.VERSION.SDK;
String s6 = Build.DEVICE;
String s7 = Build.DISPLAY;
String s8 = Build.ID;
String s9 = (new StringBuilder(String.valueOf(Build.BRAND))).append("/").append(Build.MANUFACTURER).toString();
String s10 = Build.PRODUCT;
s = (new StringBuilder(String.valueOf(s))).append("\n\n------------------\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Version: ").append(s1).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Version num: ").append(i).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Package: ").append(s2).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Phone Model: ").append(s3).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Android Version: ").append(s4).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("SDK Version: ").append(s5).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Device: ").append(s6).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Product: ").append(s10).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Brand: ").append(s9).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Disp: ").append(s7).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Id: ").append(s8).toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Available Internal memory: ").append(getAvailableInternalMemorySize()).append("/").append(getTotalInternalMemorySize()).append(" Mb").toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Heap size: ").append(getHeapSizeMb()).append(" Mb").toString();
s = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = (new StringBuilder(String.valueOf(s))).append("Mar: GO").toString();
s11 = (new StringBuilder(String.valueOf(s))).append("\n").toString();
s = s11;
android.content.pm.PackageManager.NameNotFoundException namenotfoundexception;
// namenotfoundexception.printStackTrace();
// if(true)
// goto
}
private static int getHeapSizeMb()
{
return bytesToMb(Runtime.getRuntime().maxMemory());
}
private static int getTotalInternalMemorySize()
{
StatFs statfs = new StatFs(Environment.getDataDirectory().getPath());
return bytesToMb((long)statfs.getBlockSize() * (long)statfs.getBlockCount());
}
public static void sendContactEmail(Context context)
{
String s = context.getResources().getString(0x7f040000);
String s1 = "";
String s2;
String s3;
Intent intent;
try
{
s1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
}
catch(android.content.pm.PackageManager.NameNotFoundException namenotfoundexception) { }
s2 = (new StringBuilder("[SUPPORT] ")).append(s).append(" ").append(s1).toString();
s3 = getEmailText(context);
intent = new Intent("android.intent.action.SEND");
intent.setType("plain/text");
intent.putExtra("android.intent.extra.EMAIL", new String[] {
"support@myemail.com"
});
intent.putExtra("android.intent.extra.SUBJECT", s2);
intent.putExtra("android.intent.extra.TEXT", s3);
if(context.getPackageManager().queryIntentActivities(intent, 0).size() > 0)
{
context.startActivity(Intent.createChooser(intent, "Send mail..."));
} else
{
CustomAlertDialogBuilder customalertdialogbuilder = new CustomAlertDialogBuilder(context);
customalertdialogbuilder.setTitle("Contact us");
customalertdialogbuilder.setIcon(R.drawable.ic_launcher);
customalertdialogbuilder.setMessage(Html.fromHtml("No application found to send emails.<br /><br />Please contact us at: <b>support@email.com</b>."));
customalertdialogbuilder.setNegativeButton("Close", null);
customalertdialogbuilder.show();
}
}
}