I am trying to develop a Beacon Application in Android. In that i want to get that how many times a beacon is getting scanned in one minute. I know this is possible through log. So how to get it? I am new to this and need very much so please help if anybody has answer!! Thanks in advance!
Asked
Active
Viewed 65 times
-1
-
`Log.i("Beacon", beacon.toString());` something like this u have to code. – Anand Singh Sep 09 '15 at 11:09
-
@AnandSingh I want to know with time i.e in which time each beacon got scanned . Also can i get these in csv or textfile?? Thanks!! :-) – Harsh Mittal Sep 09 '15 at 11:14
2 Answers
0
Tip: A good convention is to declare a TAG constant in your class:
private static final String TAG = "MyActivity";
Don't forget that when you make a call like
Log.v(TAG, "index=" + i);
int ASSERT Priority constant for the println method.
int DEBUG Priority constant for the println method; use Log.d.
int ERROR Priority constant for the println method; use Log.e.
int INFO Priority constant for the println method; use Log.i.
int VERBOSE Priority constant for the println method; use Log.v.
int WARN Priority constant for the println method; use Log.w.

Nooruddin Lakhani
- 7,507
- 2
- 19
- 39
0
Read the log through the following code:
public class LogTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log=new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
}
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(log.toString());
} catch (IOException e) {
}
}
}
The above code reads the log and displays it in a textview.
You should define:
<uses-permission android:name="android.permission.READ_LOGS" />
permission in your manifest.
To copy the log directly to a file,use the following method:
public static void copyLogcatToFile(Context context) {
String fileName = "log_cat"+System.currentTimeMillis()+".txt";
File outputFile = new File(context.getExternalCacheDir(),fileName);
@SuppressWarnings("unused")
Process process = Runtime.getRuntime().exec("logcat -f "+outputFile.getAbsolutePath());
}

kgandroid
- 5,507
- 5
- 39
- 69
-
I have tried exacty as you have told but it is not showing the time and also can i get it in csv format instead of txt! Thanks – Harsh Mittal Sep 09 '15 at 11:49
-
-
yh tried but i am getting everything in one line only and also the extra stuff is also there so it looks very complex! – Harsh Mittal Sep 09 '15 at 11:53