Reputation:
To Debug BroadcastReceiver when phone restart, I've tried Some Method but doesn't works and link as follow
How to debug BOOT_COMPLETE broadcast receiver's "Force Close" crashes? force-close-crashes
Upvotes: 6
Views: 617
Reputation: 3602
probably this is not the best way, but i had a similar problem and i used a sleep function of 30 seconds just at the beginning of the boot receiver onReceive method, so i had the time to go to the process list in DDMS perspective and put my app in debug mode, so the breakpoint on the first real instruction of the onReceive method it went hitted. hope this help
Upvotes: 2
Reputation: 35783
Same situation I had earlier,I wanted to know the application log details regarding Broadcast Receiver,running services or app crash etc when it was using by user in Android Device.
[so using this code you can get information like when your Broadcast Receiver start,stop,crash etc ]
I wrote my own LogCat and it's working well, and here is the code may help you
First you need to put some constants in app's constant file
public static final String LOG_DIR="/SeedSpeak/LOG";
public static final String LOG_MODE_EXCEPTION="exception";
public static final String LOG_MODE_INFO="info";
Then you need to create three method in app's Utill file
public static void MyLog(String logMode, String msgKey, Object msgValue) {
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath()+
SeedSpeakConstants.LOG_DIR);
if (!dir.exists()) {
dir.mkdirs();
}
String logFileAbsPath = dir + File.separator + "SeedSpeakLog.txt";
BufferedWriter bufferedWritter = null;
try {
bufferedWritter = new BufferedWriter(
new FileWriter(logFileAbsPath,
true));
String logValue = null;
if (logMode.equalsIgnoreCase(
SeedSpeakConstants.LOG_MODE_EXCEPTION)) {
logValue = logStackTrace((Throwable) msgValue);
} else {
logValue = msgValue.toString();
}
logValue = currentDateTimeValue() + ": " + logMode +
" :" + msgKey + ": "
+ logValue + "\n";
bufferedWritter.write(logValue);
bufferedWritter.newLine();
bufferedWritter.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String logStackTrace(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
t.printStackTrace(pw);
pw.flush();
sw.flush();
return sw.toString();
}
public static String currentDateTimeValue() {
SimpleDateFormat formatter =
new SimpleDateFormat("yyyy-mm-dd-HH:mm:ss");
formatter.setLenient(false);
Date curDate = new Date();
String curTime = formatter.format(curDate);
return curTime;
}
Now, How to use this in your project, so simple :)
Note: here TAG is just a current file (activity/service/BR) name like this
private final static String TAG = "PlantSeedActivity";
(1). for print only info (BR,Service started or not.. bla bla) log use this
SeedSpeakUtill.MyLog(SeedSpeakConstants.LOG_MODE_INFO,
TAG + ".onCreate", "Service is started now");
(2). for print exception/crash details use this way
try{
// todo here
}
catch (Exception ex)
{
SeedSpeakUtill.MyLog(SeedSpeakConstants.LOG_MODE_EXCEPTION,
TAG + ".onStartCommand", ex);
}
Now you just put app in Android device and when you want to get log details go to SeedSpeakLog.txt file and debug your application.
or one more way I heard that Google provice ACRA (Application Crash Report for Android) library
you may like to have look on this and this link
PL let me comment if you get any trouble regrading this!!
Upvotes: 0