Taking ddms logs through an application
Thanks in Advance!!
My requirement is to take ddms logs on click of a button in an app, and
save the file in sdcard.
I am able to do this through following code:
logbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
int ret = DoShellCmd("logcat -d > /sdcard/log_" +
sysdump_time + ".log");
Log.i(LOG_TAG, "returned value"+ret);
}
});
thread.start();
}
});
}
int DoShellCmd(String cmd) {
//isDumpstateRunning = true;
Log.i(LOG_TAG, "DoShellCmd : " + cmd);
Process p = null;
String[] shell_command = {
"/system/bin/sh", "-c",cmd
};
try {
Log.i(LOG_TAG, "exec command");
p = Runtime.getRuntime().exec(shell_command);
p.waitFor();
Log.i(LOG_TAG, "exec done");
} catch (IOException exception) {
Log.e(LOG_TAG, "DoShellCmd - IOException");
return -1;
} catch (SecurityException exception) {
Log.e(LOG_TAG, "DoShellCmd - SecurityException");
return -1;
} catch (InterruptedException e) {
e.printStackTrace();
return -1;
}
Log.i(LOG_TAG, "DoShellCmd done: " + cmd);
return 1;
}
Though the log file is generated , but complete logs are not appeared.
Only some logs appears. Any help will be appreciated.
No comments:
Post a Comment