Read logs of other app - android

I have two android application, (not on play store), I install both app in a mobile, Now i want to read all logs of Application1 into Application2, how can i do it,
I'm able to read inapplog, not others, using this code:
Process logcat;
final StringBuilder log = new StringBuilder();
try {
logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
BufferedReader br = new BufferedReader(new InputStreamReader(logcat.getInputStream()),4*1024);
String line;
String separator = System.getProperty("line.separator");
while ((line = br.readLine()) != null) {
log.append(line);
log.append(separator);
}
} catch (Exception e) {
e.printStackTrace();
}
Need Help.

Related

How to set default open with(dialog) option to my android app?

I have a file in my devise called test.csv. when i click on that file is opened through my app.how to set default open with(dialog) option to my app in android?
above is the sample dailog.how to add my app to the dialog list?
I think you may want to read the csv file. you could get the csv file path. So see the following.
public static void readCSV(File file) {
BufferedReader reader = null;
StringBuilder stringBuilder = new StringBuilder();
try {
InputStreamReader isr = new InputStreamReader(new FileInputStream(file));// your csv file
reader = new BufferedReader(isr);
String line = null; // every time read one line
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append("\n");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
The stringBuilder.toString() is your csv file's content. Sorry for my English.

How to capture network related logs with in the android phone

I want to know how to capture logs with in mobile phone
Does this network logs can be used to measure page load time ?
I tried capturing device logs using adb logcat in desktop but I want to capture those logs with in device
Assuming your logs are located in a String file, you can save them to a text file like this:
private void saveLogsToFile(String logs) {
try {
OutputStreamWriter out = new OutputStreamWriter(openFileOutput("saved_logs.txt", Context.MODE_PRIVATE));
out.write(logs);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
And then read them back from the file like this:
private String readSavedLogs() {
String logs = "";
try {
InputStream inputStream = openFileInput("saved_logs.txt");
if(inputStream != null) {
InputStreamReader in = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(in);
String line;
StringBuilder stringBuilder = new StringBuilder();
while((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
inputStream.close();
logs = stringBuilder.toString();
}
} catch (IOException e) {
e.printStackTrace();
}
return logs;
}

I can't read log from CallNotifier and PhoneUtils

i try read the log generated from "CallNotifier" and "PhoneUtils" but i can't,
i use two ways for this: both are thread (AsyncTask)
1:
try {
Process process = Runtime.getRuntime().exec("logcat");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("CallNotifier")) {
publishProgress(line);
}
}
}
catch (IOException e) {
}
on this way i read all catlog but i filter if the line contains "CallNotifier"
2:
try {
Process process = Runtime.getRuntime().exec("logcat -s CallNotifier");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = bufferedReader.readLine()) != null) {
publishProgress(line);
}
}
catch (IOException e) {
}
This way i filter in
exec("logcat -s CallNotifier");
Don't work
When I filter tag generated from my app the code works. if i filter from PC in terminal i can see log from CallNotifier the problem its when i filter from Android.

Filter Logs in Android programmatically

This is method to fetch and dump logs in SDCard for Android. This is working fine, but I am wondering if we can put filter to trace logs related to specific tags.
I tried logcat -s *TagIWant; but it didn't work. Any other suggestion?
public static void Log(Context context){
String filename = context.getExternalFilesDir(null).getPath() + File.separator + "my_app.log";
String command = "logcat -d *:V";
Log.d(TAG, "command: " + command);
try{
Process process = Runtime.getRuntime().exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
try{
File file = new File(filename);
file.createNewFile();
FileWriter writer = new FileWriter(file);
while((line = in.readLine()) != null){
writer.write(line + "\n");
}
writer.flush();
writer.close();
}
catch(IOException e){
e.printStackTrace();
}
}
catch(IOException e){
e.printStackTrace();
}
}
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
Pattern pattern = Pattern.compile("XXX", 0);
while ((line = bufferedReader.readLine()) != null) {
if (patternu != null
&& !pattern.matcher(line).find()) {
continue;
}
log.append(line);
log.append('\n');
}
} catch (IOException e) {
}
Replace "Your_Tag" with your tag, that will give you the logs with tag as specified in with priority "Debug" and Above.
String command = "logcat Your_Tag:D *:S";
Process process = Runtime.getRuntime().exec(command);
Check more on http://developer.android.com/tools/debugging/debugging-log.html
You can easily filter the line that you want to write like the code below:
while ((line = bufferedReader.readLine()) != null) {
if(line.contains("The String you want to exist in your log")){
writer.write(line + "\n");
}
else{continue;}
}

Save app event (logcat) in file on sd

I want to save my app logcat events in a text file on sd card.
my alarming app work properly in my and my friends devices, but other have error on my app.
for example they say alarms in app are in wrong time, but i dont see this error in my and my friends devices.
Because of this issue and other issues, i want save all events logcat related my app, atomatically. so they send log file to me to solve issues.
how can i do this?
thanks
sorry for my bad english
You can get logcat via the following:
static final int BUFFER_SIZE = 1024;
public String getLogCat() {
String[] logcatArgs = new String[] {"logcat", "-v", "time"};
Process logcatProc = null;
try {
logcatProc = Runtime.getRuntime().exec(logcatArgs);
}
catch (IOException e) {
return null;
}
BufferedReader reader = null;
String response = null;
try {
String separator = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), BUFFER_SIZE);
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append(separator);
}
response = sb.toString();
}
catch (IOException e) {
}
finally {
if (reader != null) {
try {
reader.close();
}
catch (IOException e) {}
}
}
return response;
}
You can then save this String to the sdcard.
You can get logcat via the following:
static final int BUFFER_SIZE = 1024;
public String getLogCat() {
String[] logcatArgs = new String[] {"logcat", "-v", "time"};
Process logcatProc = null;
try {
logcatProc = Runtime.getRuntime().exec(logcatArgs);
}
catch (IOException e) {
return null;
}
BufferedReader reader = null;
String response = null;
try {
String separator = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), BUFFER_SIZE);
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append(separator);
}
response = sb.toString();
}
catch (IOException e) {
}
finally {
if (reader != null) {
try {
reader.close();
}
catch (IOException e) {}
}
}
return response;
}
You can then save this String to the sdcard.
This answer from "Dororo" didn't work for me since it always got stuck in the while due to to many lines, but i have no idea how to fix that.
the logcat will block for reading new logs unless you specify the '-d' arg.
try
String[] logcatArgs = new String[] {"logcat", "-d", "-v", "time"};
This type of functionality is already implemented by the ACRA Android library. The library detects crashes, and send the crash information to either a Google Docs spreadsheet, or your own destination.
Execute within a thread to avoid ANRs

Categories

Resources