This question already has answers here:
capturing and sending logcat output by email or to server
(2 answers)
Closed 9 years ago.
I installed the .apk file in the device then run that application at this time suppose i am getting any exception then application will be crash. At this time i want to see that exception in the device without using Eclipse Logcat. It means i want send that exception to file(means some path in the device like sdcard/downloads/a.txt)in the device using Log.
Generally some applications are working properly in the emulator but in case of device we got some exceptions. so thats why i want see that particular exception in the device using Log.
Is it possible? How can i implement this? can anybody help me.
Myapplication classs:
package com.ibkr.roadbrake;
import org.acra.*;
import org.acra.annotation.*;
import android.app.Application;
import android.os.Bundle;
#ReportsCrashes(formKey = "dDJ5VFhURVNHakhSa3hfTndteFd6Smc6MQ")
public class MyApplication extends Application
{
#Override
public void onCreate()
{
// The following line triggers the initialization of ACRA
ACRA.init(this);
super.onCreate();
}
public Bundle getCrashResources()
{
Bundle result = new Bundle();
String RES_TOAST_TEXT = null;
result.putInt(RES_TOAST_TEXT, R.string.crash_toast_text);
return result;
}
}
thanks
Log4j or slf4j can also be used as logging frameworks in Android together with logcat. See the project android-logging-log4j and log4j support in Android. Configuring logging to a (rotating) file(s) is very easy.
static {
final LogConfigurator logConfigurator = new LogConfigurator();
logConfigurator.setFileName(Environment.getExternalStorageDirectory() + "myapp.log");
logConfigurator.setRootLevel(Level.DEBUG);
// Set log level of a specific logger
logConfigurator.setLevel("org.apache", Level.ERROR);
logConfigurator.configure();
}
Related
I am new to Android Studio. I successfully created a Hello World app from the example in Android website. Now, I want to play around by using some statement to print in the logcat but it doesn't works. Below is my ApplicationTest.java code:
package com.example.abc.myloggingapplication;
import android.app.Application;
import android.test.ApplicationTestCase;
import android.util.Log;
/**
* Testing Fundamentals
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
Log.d("MyTest", "Here goes the output!"); // THIS IS THE NEW STATEMENT INSERTED BUT PRINTS NOTHING IN CONSOLE LOG IN ANDROID STUDIO SDK.
}
}
Other files are same as provided by the Hello World example in Android website. In Android Studio sdk, I entered the logcat to debug but still no luck. Can anybody point me out where I am going wrong.
Check your logcat:
Check View -> Tool windows -> Android Monitor.
Or Alt + 6
If that doesnt help, make sure you have an instance of your class. Otherwise the constructor is never called and therefor the log.d is never called.
Edit:
As other's have stated: Check if you are running the Test Application, if you want to do so. Otherwise make sure you code in your actual application and not your test application.
I'm working with espresso for testing. I'm following Espresso Intents
and problem happened when I try to work like this site. First is validateIntentSentToPackage method:
public void validateIntentSentToPackage() {
user.clickOnView(system.getView(R.id.callButton));
intended(toPackage("com.android.phone"));}
Android Studio display error at "user" and "system". I don't understand this error what does this mean.
Second is activityResult_IsHandledProperly method:
public void activityResult_IsHandledProperly() {
Intent resultData = new Intent();
String phoneNumber = "123-345-6789";
resultData.putExtra("phone", phoneNumber);
ActivityResult result = new ActivityResult(Activity.RESULT_OK, resultData);
intending(toPackage("com.example.unittestdemo")).respondWith(result));
onView(withId(R.id.pickButton)).perform(click());
onView(withId(R.id.phoneNumber).check(matches(withText(phoneNumber)));}
Android Studio display error java.lang.NullPointerException and in line intending(toPackage("com.example.unittestdemo")).respondWith(result);
Please help!!!
Android Studio display error at "user" and "system". I don't understand this error what does this mean.
I guess, you don't have previously declared these variables.
I don't see any logs or whole code of this testing class, so I can only recommend you to check this example
Here you would find all methods which you're looking for in one file.
Also please visit Google Samples - Espresso Testing repository
Is there a way to view the log on a tablet running 4.4? I've downloaded several apps like aLogCat and none of them show what my app writes out with S.o.p or Log.d. I have an intermittent bug that gives the Unfortunately appname has stopped message.Is there any way to view the log after this event without having to connect to a PC and use the adb program?
What other ways are there to get debug output? Would trapping the System.out and System.err classes get the stack trace?
Thanks,
Norm
You're focussing on tring to read out logcat, but there are better solutions for reading crash logs. My personal preference is Crashlytics, which automatically logs fatal exceptions and provides mechanisms for logging other messages.
The way all these crash reporters work, is by defining a UncaughtExceptionHandler:
Thread.setDefaultUncaughtExceptionHandler(
new MyUncaughtExceptionHandler(this));
If you prefer to use your own solution, you may want to look into using this. See this related question for more details.
Is there a way to view the log on a tablet running 4.4?
No, sorry. An app can only see its own log messages, not those from other apps. Hence, a third-party log viewer cannot see your app's messages.
Is there any way to view the log after this event without having to connect to a PC and use the adb program?
Use any standard crash management library, like ACRA, or services like Crashlytics, BugSense, etc.
The AIDE Application (Android Integrated Development Environment) allows one to develop android Apps directly on android device.
One particular feature is to read the logcat.
You can get it here https://play.google.com/store/apps/details?id=com.aide.ui
Here's the code I've put in the program. It seems to work:
// Define inner class to handle exceptions
class MyExceptionHandler implements Thread.UncaughtExceptionHandler {
public void uncaughtException(Thread t, Throwable e){
java.util.Date dt = new java.util.Date();
String fn = LogFilePathPfx + "exception_" + sdf.format(dt) + ".txt";
try{
PrintStream ps = new PrintStream( fn );
e.printStackTrace(ps);
ps.close();
System.out.println("wrote trace to " + fn);
e.printStackTrace(); // capture here also???
SaveStdOutput.stop(); // close here vs calling flush() in class
}catch(Exception x){
x.printStackTrace();
}
lastUEH.uncaughtException(t, e); // call last one Gives: "Unfortunately ... stopped" message
return; //???? what to do here
}
}
lastUEH = Thread.getDefaultUncaughtExceptionHandler(); // save previous one
Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler());
I just set up ACRA for exception reporting on Android, and on my local simulator, I get this exception:
and here is my class:
package com.problemio;
import android.app.Application;
import org.acra.*;
import org.acra.annotation.*;
#ReportsCrashes(formKey = "...")
public class MyApplication extends Application
{
#Override
public void onCreate()
{
// The following line triggers the initialization of ACRA
ACRA.init(this);
super.onCreate();
}
}
How should I change the code to make it right? Thanks!!!
Making my comment an answer, because it solved the issue:
Such spread sheet does not exist, or at least when I point my browser to this address (https://spreadsheets.google.com/formResponse?formkey=0AteWveJtbl4GdDA2WWsyRE5NbEtJM2hmbmd5NVhxM3c&ifq) it says so. Make sure you have the form key entered correctly.
I have a PhoneGap application that works fine but occasionally is known to have bugs. I would like to catch them and send them to a Google Doc with ACRA
I have been following the ACRA wiki steps here http://code.google.com/p/acra/wiki/BasicSetup?tm=6
The ACRA documentation says I should create an Application class and then point my AndroidManifest at it by naming the Application the same as that class.
That didn't work, or at least it didn't catch any errors I tested it with.
I thought this would be the best bet, but it isn't logging anything and still Force Closes the app when I force a NullPointer exception error.
#ReportsCrashes(formKey = "dFhqOGY3cVVGc0w4UUxGa2E2Y3RL...",
mode = ReportingInteractionMode.NOTIFICATION)
public class myPhoneGap extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
ACRA.init(this.getApplication());
super.onCreate(savedInstanceState);
super.init();
super.loadUrl("file:///android_asset/www/index.html");
}
}
I'm pretty sure you have to set up another activity that extends Application like this:
package jq.test;
import android.app.Application;
import org.acra.*;
import org.acra.annotation.*;
#ReportsCrashes(formKey = "xxxxxxxxxxxxxxxxxxxxxxxxx")
public class MyApplication extends Application {
#Override
public void onCreate() {
// The following line triggers the initialization of ACRA
ACRA.init(this);
super.onCreate();
}
}
and then in your manifest change the name of the application to the name of the class. I'm pretty sure that that's it but I have a question for you.....how do you get the formkey from Google Docs? I can't remember how to do that lol and its not posted anywhere. It really should be in the acra wiki but its not.