How to use Eclipse interactive console in debug - android

I'm trying to play with debug in Android app and, when a breakpoint is encountered, Eclipse shows me a lot of windows, one of which is the "Interactive Console" with a prompt: I think to be able to enter statements and/or other stuff, but it seems to be disabled.
How can I work with it?

Window - Show View - Debug - Display
That will provide you with a window to enter statements and execute/inspect them.
This is a feature that's available in core eclipse platform. It works in most cases for Android based projects as well.
More info on the display view can be found here : http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/views/debug/ref-debug_view.htm
For a nice overview of the debugging features of Eclipse, check out this post : http://www.cavdar.net/2008/09/13/5-tips-for-debugging-java-code-in-eclipse/

The "Interactive Console" within the Debug View of Eclipse is used whenever the debugged program expects some input from the console.

It's possible you have other plugins installed that provide that view, and it's not meant to be used by Android Java code. See here (not accepted answer, but community-favored one).

You can use Logcat for and can see your check points using
android.util.Log.e("","CheckPoint");
You can toast your check points using Toast like:
Toast.makeText(this, "Write here what you want see",1 or 0).show();
1-> long time displaying and 0 for short time.
This toast display in your device screen when programe running.
You can use console screen for seeing output like print statements Ex---
java.lang.System.out.print("Checking");

use
try{
statements...;
}
catch(Exception e){
System.out.println("the error message "+e);
}
will show the error messages.

Related

What is the best practice using Android Logger

I am new to Android. Please help me to know about the best practice of using Android Logger. Do I need to keep a file somewhere in android and keep on writing logs into it, or writing of logs into file is not necessary. What could be the best practice.
My real intention is this.
Once we go live, if our customers come back and tell us that something crashed or does not work in their android , then how do we debug ?
In the web application, I would ask my server administrator to provide the log files. What do we do with the android application when there is no server error, but something failed in the phone. Is there a way to get logs from the phone.
Thanks
Ravi
Depends on what you need, you need logging for semi debugging your application than you can easily use the buildin Log functionality. Via Logcat you can easiliy see the logs.
http://www.vogella.com/tutorials/AndroidLogging/article.html
//Declare a tag
String TAG= "SomeActivity";
//Log
Log.d(TAG, "Hello World"); //debug
Log.e(TAG, "Hello World"); //error
If you want to have logging of multiple devices when you have released your app. Use a dedicated Log Framework (e.g. Log4J) and upload it to a server.
One tip (if you are using Eclipse, and not directly related to question) - Eclipse is very unreliable for viewing logs. For apparently no reason it completely stops displaying logs every now and then. A simple solution is to use command line tools for viewing logs. On Linux you can do :
$adb logcat MyTag:D *:S
If you want to capture logs to a file you can do:
$adb logcat -d > logcat.txt.
Hope this helps!
If you are planning to publish/distribute your application then storing logs in a file is possible but as per my opinion better not a better solution. You can configure online tools from your app.
Catch all sever exceptions and sending all the details regarding that exception. And configure any one logging tool into you application.
You can see log4j http://logging.apache.org/log4j/2.x/ or ACRA http://acra.ch/ or http://www.crittercism.com/
The Android logger's (android.util.Log) output goes to a console that you don't have to maintain. You don't actually have to manage files, just outputs.
You have 5 categories of log:
verbose: use Log.v(tag, message)
debug: use Log.d(tag, message)
info: use Log.i(tag, message)
warning: use Log.w(tag, message)
error: use Log.e(tag, message)
For example:
Log.e("MyActivity", "Oops... caught this exception: " + exception.getMessage());
The LogCat console (this is its name) allows you filtering by log level. This is a ceil filtering. For example, if you filter by 'warnings', you will see all warnings and errors, but not verbose, debug and info messages.
You'll find more details here in the official documentation.
My real intention is this.
Once we go live, if our customers come back and tell us that something crashed or does not work in their android , then how do we debug ?
In the web application, I would ask my server administrator to provide the log files. What do we do with the android application when there is no server error, but something failed in the phone. Is there a way to get logs from the phone.
If you use file for storage logs - it possible problem with performance if the file become big. So you need clean file in time.
As for me best solution use firebase or https://fabric.io/.
We use fabric.io.
Also you can use some wrapper for default Log class. This one https://github.com/JakeWharton/hugo for example

Reading Log from android app through Robotium test project

I need to read the logs from the android application project through robotium test project. Please help me out.
Thanks
If you want to see the logs , Please use logcat, in Eclipse(that comes with android SDK).
Go To:
Window --> Show View --> other --> search LogCat
In LogCat you can see the logs for both Application under test and your test project. To use android's inbuilt logging library , you can do something like Log.d ("I am a Log");
In LogCat you can filter your preferred logs by creating a filter by clicking on the + button there.
If you want to wait for some log to appear or assert some log messages use the following methods:
solo.waitForLogMessage(String logMessage, int timeout);

Unity Facebook SDK v5.1 cannot login on android device

I get the trouble with using Facebook SDK on android. Below is what I have done:
I'm using Facebook sdk 5.1.0 and Unity version is 4.3.4
In Assets\Facebook\Editor\android\FacebookAndroidUtil.cs, I add
System.Environment.GetEnvironmentVariable("HOMEDRIVE") in line 62
so that "Debug Android Key Hash" can be generated.
I using C# to type the main script, in "Awake()" I add
FB.Init(SetInit, InitCallback);. It just like the tutorial from
developers.facebook.com, and enable is give out "true". (I think
that mean FB.init() is success.)
After that, I build up a GUI button for log in. I have try FB.Login("basic_infos", AfterLogin);, FB.Login("publish_actions", AfterLogin); and FB.Login("email", AfterLogin); , both the FB.isLoggedIn is false on android device.
Actually I can log in on unity environment using "User Access Token". On android device, after I press the Login button, it give out a permission and then I press "OK", nothing happen...(FB.isLoggedIn still false)
Anyone can give a help? I get the trouble a few week already...
p.s. My English is not good, please let me know if you don't understand.

Track APP Installs from Facebook

I'm following documentation as states:
https://developers.facebook.com/docs/ads-for-apps/mobile-app-ads/#advanced
Specifically: Measure App Installs
However, I did the following code:
com.facebook.AppEventsLogger.activateApp( this, APPLICATION_ID_FACEBOOK );
However, in dashboard, it doesn't detect the install:
Any tips?
LogCat outputs the following:
FacebookException: No attribution id returned from the Facebook application
Ok. Solved.
Basically for whoever faces this:
FACEBOOK APP must be installed in device.
USER must be logged in.
Thats it.
=)
Another great but hidden hint is to enable verbose logging via
FacebookSdk.addLoggingBehavior(APP_EVENTS)
The output is actually very helpful and even contains error analysis and descriptions.

Android: Make the app logs my logging statements "only"

I am planning on signing an apk and releasing it (through Export Eclipse tool). Then upload it to the market. I know that debuggable is set to false by default when signing it so that means that no logs will be captured. At the same time, if I set debuggable to true and release the apk then I will get all the logs.
What I am really interested in is the last debug statement that are added by me only. Currently, I am using the Log.i statement to add info logs. Is there a way to have my app logging only the Info logs (i.e. my logs only). Mybe if I disable the log and have system.out.print it would work?
The reason I am doing this is becuase I want to send the last 100 lines of log when a crash happens and I am only interested in my log statments.
Please help me out
Thanks
I believe what you need to do is take advantage of ACRA's built in filtering functionality:
In the Advanced Usage wiki you can see that you can set your logcat arguments in your config.
In your logging, tag your custom log messages with a specific tag and debug level, then in the logcat arguments, then set a parameter:
logcatArguments = { "-t", "100", "-v", "long", "ActivityManager:I", "MyApp:D", "*:S" }
add one in the form of
"YourCustomTag:<YOUR_DEBUG_LEVEL>"
and take out the ones you don't want to be logged (probably MyApp:D in this case.)
You will have to put a wrapper on top of Log where you can put functionality to control the log levels.
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. You can add additional information like the past 100 lines of your log using the method shown here.

Categories

Resources