I can't read log from CallNotifier and PhoneUtils - android

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.

Related

Read logs of other app

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.

start test apk in another apk

Android version: 4.1 .
I want to test my apk without pc, so i write android apk to do it.
Process proc = Runtime.getRuntime().exec(command);
try {
if (proc.waitFor() != 0) {
System.err.println("exit value = " + proc.exitValue());
// proc.waitFor();
}
BufferedReader in = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
stringBuffer.append(line+"\n");
}
// proc.waitFor();
System.out.println(stringBuffer.toString());
Log.i("info",stringBuffer.toString());
return stringBuffer.toString();
} catch (InterruptedException e) {
System.err.println(e);
}
and the command is
am instrument -w -e deleteCase no com.calculator.test/com.xx.test.runner.Runner1
but it's not worked.

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;
}

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;}
}

Alternatives to calling ping executable from Java on Android

I am using the following code to call android equipment ping command:
public static String pingServer() {
PingResult result = new PingResult();
String jsonString = null;
try {
String command = "ping -c 3 192.168.8.185";
Process p = Runtime.getRuntime().exec(command);
int status = p.waitFor();
InputStream input = p.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = in.readLine()) != null) {
buffer.append(line);
buffer.append("\n");
}
String bufferStr = buffer.toString();
System.out.println(bufferStr);
} catch (Exception e) {
System.out.println("---------------exception-----------ping");
System.out.println(e.getMessage());
// e.printStackTrace();
}
}
BufferStr always obtain the last line data.
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
The details result can be get.
It may be simpler and easier to use InetAddress.isReachable:
if (InetAddress.getByName("192.168.8.185").isReachable(6000))
...

Categories

Resources