Android, adding ACRA support

209 views
Skip to first unread message

dbnex B

unread,
Oct 26, 2015, 9:39:37 PM10/26/15
to acra-discuss


I am trying to implement ACRA in my test app (Android API 5.1 Lollopop) in Android Studio to show a notification, a dialog or any other way to show report but I do not have any server and at the moment would like not to use acralyzer.  However, following the instructions in BasicSetup in ACRA documentation, I was not able to figure it out.

So far, I implemented following:

1. Added dependency in gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "study.android.acratest"
        minSdkVersion 22
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'

    //ACRA https://github.com/ACRA/acra.git
    compile 'ch.acra:acra:4.6.2'
}


 

2. Added MyApplication class.  I am intending to use a notification below but from reading documentation, I was not able to figure out if ReportCrashes below is properly set:

package study.android.dino.acratest;

import android.app.Application;
import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;

@ReportsCrashes(

  //formKey="", //Android Studio reports this as “Cannot resolve”
  //mode = ReportingInteractionMode.DIALOG, // I tried using this but same result
  resNotifTickerText = R.string.crash_notification_ticker_text,
  resNotifTitle = R.string.crash_notification_title,
  resNotifText = R.string.crash_notification_text,
  resNotifIcon = R.mipmap.error)
public class MyApplication extends Application {

    private static final String TAG = MyApplication.class.getSimpleName();

    @Override
    public void onCreate(){
        super.onCreate();

        ACRA.init(this);
    }
}



3. Added MyApplication to AndroidManifest and added INTERNET permission:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="study.android.acratest" >

    <!-- add INTERNET permission -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- add application name -->
    <application
        android:name="MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


 

4. My main activity has just Error button which will throw Arithmetic Exception when it attempts to do division by zero:

package study.android.acratest;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public final static String TAG = MainActivity.class.getSimpleName();

    private Button btnError;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnError = (Button) findViewById(R.id.btnError);
        btnError.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), getString(R.string.toast_app_crash)

                , Toast.LENGTH_SHORT).show();

                Runnable r = new Runnable() {
                    @Override
                    public void run() {
                        // this will crash your app throwing Arithmetic Exception
                        int number = 7 / 0;
                    }
                };

                Handler h = new Handler();
                h.postDelayed(r, 2000);
            }
        });
    }
}


I am expecting to see some kind of notification and some kind of report to get generated but I dont get any. My app simply crashes at the spot where division by zero is attempted.

I am not sure what is that I am doing wrong.

Thanks,

dbnex B

unread,
Oct 26, 2015, 9:51:34 PM10/26/15
to acra-discuss
... btw, I have also tried using

@ReportsCrashes(
mailTo = "myemail...@gmail.com",
mode = ReportingInteractionMode.DIALOG,
resDialogText = R.string.crash_notification_text)

but that did not send anything to my email address either.

William Ferguson

unread,
Oct 27, 2015, 6:14:54 PM10/27/15
to acra-discuss
To send a report to a server you need to populate `formUri` with the address of that server. Otherwise ACRA has nowhere to post the crash report to.

William
Reply all
Reply to author
Forward
0 new messages