2012-12-24 30 views
8

是否有人知道如何修改“强制关闭”窗口的样式(FC对话框)? 我在对话框中找到了一张带有漂亮图片的自定义ROM。在什么地方我可以找到弹出窗口?如何修改android“强制关闭”窗口的样式?

+0

http://stackoverflow.com/questions/7533932/how-to-make-the-force-close-window-显示友好的应用程序名称而不是一个包装 –

+3

我会建议你避免强制关闭对话框,而不是造型它:) –

回答

3

尝试重写uncaughtException,

@Override 
public void uncaughtException(Thread thread, Throwable e) { 
e.printStackTrace();  

    try {  

     // create your custom dialog 
     displayErrorMessageToast(); 

     Thread.sleep(3500);  
    } catch (Exception e1) {  
     Log.e(TAG, "Error: ", e1);  
    } 
    finally 
    {  
     killApplicationProcess(e);  
    } 
} 

更多信息: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/2iUH1Knz8gw

+0

但这是不可改变的所有系统FC对话框样式这种方式。我只需要修改fc对话框样式。 – neverchange

+0

如果你在@Praful Bhatnagar的回答里找到了,你可以编写你自己的UnCaughtException.java并为你的活动设置线程,像这样:Thread.setDefaultUncaughtExceptionHandler(new UnCaughtException(youractivity.this)); – Talha

+0

非常感谢,该答案只能修改一个应用程序FC对话框样式。但我想要更改所有系统应用程序fc对话框样式。 – neverchange

0

尝试在此blog

复制为快速参考在这里给出的方法:

的Android UncaughtExceptionHandler

由希望处理线程由未捕获的异常终止的情况的对象实现。在这种终止时,处理程序被通知终止线程和因果异常。如果没有显式的处理程序集,那么该线程的组是默认处理程序。

下面我编写了代码,用户可以在应用程序崩溃时向开发人员发送一些错误报告。

活动代码

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 
import android.widget.ViewFlipper; 
/** 
* 
* @author vijayakumar 
* 
*/ 
public class AndroidMADQAActivity extends Activity { 
ViewFlipper flipper; 
TextView textView = null; 
Throwable throwable; 
UnCaughtException un = null; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
Thread.setDefaultUncaughtExceptionHandler(new UnCaughtException(AndroidMADQAActivity.this)); 
Integer[] items = { R.drawable.a, R.drawable.e,R.drawable.d,R.drawable.c}; 
setContentView(R.layout.main); 
textView.setText("Helloo Error Welcome"); 
} 
} 

UnCaughtException.java

package com.madqa; 
import java.io.File; 
import java.io.PrintWriter; 
import java.io.StringWriter; 
import java.io.Writer; 
import java.lang.Thread.UncaughtExceptionHandler; 
import java.util.Date; 
import java.util.Locale; 
import android.app.AlertDialog; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.pm.PackageInfo; 
import android.content.pm.PackageManager; 
import android.net.Uri; 
import android.os.Environment; 
import android.os.Looper; 
import android.os.StatFs; 
import android.util.Log; 
/** 
* {@link UncaughtExceptionHandler} send an e-mail with 
* some debug information to the developer. 
* 
* @author VIJAYAKUMAR 
*/ 
public class UnCaughtException implements UncaughtExceptionHandler { 
private static final String RECIPIENT = "[email protected]"; 
private Thread.UncaughtExceptionHandler previousHandler; 
private Context context; 
private static Context context1; 
public UnCaughtException(Context ctx) { 
context = ctx; 
context1 = ctx; 
} 

private StatFs getStatFs() { 
File path = Environment.getDataDirectory(); 
return new StatFs(path.getPath()); 
} 
private long getAvailableInternalMemorySize(StatFs stat) { 
long blockSize = stat.getBlockSize(); 
long availableBlocks = stat.getAvailableBlocks(); 
return availableBlocks * blockSize; 
} 
private long getTotalInternalMemorySize(StatFs stat) { 
long blockSize = stat.getBlockSize(); 
long totalBlocks = stat.getBlockCount(); 
return totalBlocks * blockSize; 
} 
private void addInformation(StringBuilder message) { 
message.append("Locale: ").append(Locale.getDefault()).append('\n'); 
try { 
PackageManager pm = context.getPackageManager(); 
PackageInfo pi; 
pi = pm.getPackageInfo(context.getPackageName(), 0); 
message.append("Version: ").append(pi.versionName).append('\n'); 
message.append("Package: ").append(pi.packageName).append('\n'); 
} catch (Exception e) { 
Log.e("CustomExceptionHandler", "Error", e); 
message.append("Could not get Version information for ").append(
context.getPackageName()); 
} 
message.append("Phone Model: ").append(android.os.Build.MODEL).append(
'\n'); 
message.append("Android Version: ").append(
android.os.Build.VERSION.RELEASE).append('\n'); 
message.append("Board: ").append(android.os.Build.BOARD).append('\n'); 
message.append("Brand: ").append(android.os.Build.BRAND).append('\n'); 
message.append("Device: ").append(android.os.Build.DEVICE).append('\n'); 
message.append("Host: ").append(android.os.Build.HOST).append('\n'); 
message.append("ID: ").append(android.os.Build.ID).append('\n'); 
message.append("Model: ").append(android.os.Build.MODEL).append('\n'); 
message.append("Product: ").append(android.os.Build.PRODUCT).append(
'\n'); 
message.append("Type: ").append(android.os.Build.TYPE).append('\n'); 
StatFs stat = getStatFs(); 
message.append("Total Internal memory: ").append(
getTotalInternalMemorySize(stat)).append('\n'); 
message.append("Available Internal memory: ").append(
getAvailableInternalMemorySize(stat)).append('\n'); 
} 
public void uncaughtException(Thread t, Throwable e) { 
try { 
StringBuilder report = new StringBuilder(); 
Date curDate = new Date(); 
report.append("Error Report collected on : ").append(curDate.toString()).append('\n').append('\n'); 
report.append("Informations :").append('\n'); 
addInformation(report); 
report.append('\n').append('\n'); 
report.append("Stack:\n"); 
final Writer result = new StringWriter(); 
final PrintWriter printWriter = new PrintWriter(result); 
e.printStackTrace(printWriter); 
report.append(result.toString()); 
printWriter.close(); 
report.append('\n'); 
report.append("**** End of current Report ***"); 
Log.e(UnCaughtException.class.getName(), 
"Error while sendErrorMail"+report); 
sendErrorMail(report); 
} catch (Throwable ignore) { 
Log.e(UnCaughtException.class.getName(), 
"Error while sending error e-mail", ignore); 
} 
// previousHandler.uncaughtException(t, e); 
} 
/** 
* This method for call alert dialog when application crashed! 
* @author vijayakumar 
*/ 
public void sendErrorMail(final StringBuilder errorContent) { 
final AlertDialog.Builder builder= new AlertDialog.Builder(context); 
new Thread(){ 
@Override 
public void run() { 
Looper.prepare(); 
builder.setTitle("Sorry...!"); 
builder.create(); 
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
@Override 
public void onClick(DialogInterface dialog, int which) { 
System.exit(0); 
} 
}); 
builder.setPositiveButton("Report", new DialogInterface.OnClickListener() { 
@Override 
public void onClick(DialogInterface dialog, int which) { 
Intent sendIntent = new Intent(Intent.ACTION_SEND); 
String subject = "Your App crashed! Fix it!"; 
StringBuilder body = new StringBuilder("Yoddle"); 
body.append('\n').append('\n'); 
body.append(errorContent).append('\n').append('\n'); 
// sendIntent.setType("text/plain"); 
sendIntent.setType("message/rfc822"); 
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { RECIPIENT }); 
sendIntent.putExtra(Intent.EXTRA_TEXT, body.toString()); 
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 
sendIntent.setType("message/rfc822"); 
// context.startActivity(Intent.createChooser(sendIntent, "Error Report")); 
context1.startActivity(sendIntent); 
System.exit(0); 
} 
}); 
builder.setMessage("Unfortunately,This application has stopped"); 
builder.show(); 
Looper.loop(); 
} 
}.start(); 
} 
} 
+0

谢谢,但我仍然想改变系统FC对话框样式。您为应用程序工作得很好的方式。我想要系统级别的改变。如:可能是dalvik捕捉到一个异常,它调用fc对话框。我需要改变对话框样式。 – neverchange