Reading logs programatically
Writing logs into logcat from yuor application is quite easy, reading the logcat programmatically is just a bit more tricky.
Reading logs is usually used for bugreport purposes.

The following code reads logs and displays then in a TextView:
- public class LogTest extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- try {
- 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());
- }
- }
- }
When I first fint this solution, I was afraid that it will require some extreme permission because it runs logcat like a console command.
Fortunatelly there is a permission for reading logs:
- <uses-permission android:name="android.permission.READ_
LOGS" />
You can add any more parameters to the logcat command string, just like it is defined in the documentation.
When implementing a bugreport feature, with sending logs to yuorself, dont forget that many applications outputs personal information into the logcat, so a policy about them is definetly needed.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@StephanieNich10 (Stephanie Nichols)#android I laughed so hard at ochocinco 's avi. Hahahaha http://t.co/MPuhhi3m
25 weeks 5 days ago -
@CarlaAtkins8 (Carla Atkins)#android Omg! This is actually f'n interesting http://t.co/JodMOehr
25 weeks 5 days ago -
@MarianMcleod12 (Marian Mcleod)#android Precisely what song is? http://t.co/YmJXU0rB
25 weeks 5 days ago -
@JoBeach15 (Jo Beach)#android haha this made me laugh, i love ted:-) http://t.co/gtcWQ79C
25 weeks 5 days ago -
@aochart3 (青ちゃ)Start playing Paradise Island on Android http://t.co/DEID0Ao5 #Android #Androidgames #Gameinsight http://t.co/e1bifSeL
25 weeks 5 days ago
Poll
Useful resources
Android Development Projects
- Android bases applications development (only indian & very skilled developers apply) by sudhirjeet01
- Health Care App - want freelancer in Georgia by rshearer
- IOS+Android+HTML5+PHP Expert Needed Urgently by johnusa1
- NFC Keyboard Wedge by billinginfoes
- I need an iphone and android app + web services by senjy
- Mobile Remote control software for android only by leoagent786
- Add a "Print" button, with code, to our existing process (PDF explains) by sportingchance
- I need a phone app - Android and Iphone - a copy of an existing app by DooniseP
- Apple & Android app - Connecting our CRM and an external GPS device by kshyamnatraj
- Flash&Actionscript app for android by mobistar2013



