How to implement acra error report on activity or something else? I know it must be on class that extends application, but is it possible to add acra to activity?
I'm getting the following error
cannot be cast to android.app.application
This is my code
#ReportsCrashes(
formUri = "http://test.com/cekErr",
formUriBasicAuthLogin = "GENERATED_USERNAME_WITH_WRITE_PERMISSIONS",
formUriBasicAuthPassword = "GENERATED_PASSWORD",
formKey = "",
customReportContent = {
ReportField.APP_VERSION_CODE,
ReportField.APP_VERSION_NAME,
ReportField.ANDROID_VERSION,
ReportField.PACKAGE_NAME,
ReportField.REPORT_ID,
ReportField.BUILD,
ReportField.STACK_TRACE
},
resToastText = R.string.app_name
)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ACRAConfiguration config = ACRA.getNewDefaultConfig(this.getApplication());
config.setResToastText(R.string.app_name);
ACRA.setConfig(config);
ACRA.init(this.getApplication());
Map<ReportField, String> mapping = new HashMap<ReportField, String>();
mapping.put(ReportField.APP_VERSION_CODE, "myAppVerCode");
mapping.put(ReportField.APP_VERSION_NAME, "myAppVerName");
mapping.put(ReportField.LOGCAT, "myAppErr");
// ...
mapping.put(ReportField.USER_EMAIL, "userEmail");
// remove any default report sender
ACRA.getErrorReporter().removeAllReportSenders();
// create your own instance with your specific mapping
ACRA.getErrorReporter().addReportSender(
new HttpPostSender
("http://test.com/cekErr"
, mapping));
}
You don't need to add acra to and activity you need to configure to an application class level.
MyApplication.java
import org.acra.*;
import org.acra.annotation.*;
#ReportsCrashes(
formKey = "", // This is required for backward compatibility but not used
formUri = "http://www.backendofyourchoice.com/reportpath"
)
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
Application
<application android:icon="#drawable/icon" android:label="#string/app_name" android:name="MyApplication">
Permition
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
follow this basic setup
No. ACRA is added to your entire application.
If you don't already have an Application class just create one that extends from Application.
As colleagues already have told you, ACRA is added to entire application. So, add ACRA to your app, but use it only in desired Activity.
Related
As you know Android Developers:
Beginning March 1, 2017, Google Play will block publishing of any new apps or updates where PreferenceActivity classes may be vulnerable to Fragment Injection
In the page https://support.google.com/faqs/answer/7188427 it gives some advices on how to fix this vulnerability but what about the applications developed with Xamarin?
I haven't been able to found any information on this. It says that my affected class is SettingActivity, which inherits from PreferenceActivity, and my class SettingActivity is this:
[Activity(
Label = "#string/ApplicationName",
Icon = "#drawable/ic_launcher",
Theme = "#android:style/Theme.Holo.Light",
ParentActivity = typeof(MainActivity))]
[IntentFilter(
new [] {Intent.ActionManageNetworkUsage},
Categories= new [] {Intent.CategoryDefault}
)]
public class SettingsActivity : PreferenceActivity
{
public static readonly string KeyWifiOnly = "pref_wifi_only";
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
AddPreferencesFromResource(Resource.Xml.preferences);
ActionBar.SetHomeButtonEnabled(true);
ActionBar.SetDisplayHomeAsUpEnabled(true);
PreferenceManager.SetDefaultValues(this, Resource.Xml.preferences, false);
SetupNetworkPreferences();
}
private void SetupNetworkPreferences()
{
var prefs = PreferenceManager.GetDefaultSharedPreferences(this);
ListPreference list = FindPreference(
AppSettings.PreferenceNetworkProvider) as ListPreference;
list.SetEntries(
Enum.GetNames(typeof(AppSettings.FtpHostNetwork)));
list.SetEntryValues(Enum
.GetValues(typeof(AppSettings.FtpHostNetwork))
.Cast<int>()
.Select(x => x.ToString())
.ToArray());
}
protected override void OnResume()
{
base.OnResume();
var tracker = (Application as App).Tracker;
tracker.Screen("PantallaPreferencias");
}
}
As suggested by Mike Ma in the comments:
Adding the exported=false propierty worked just fine.
[Activity( Label = "#string/ApplicationName", Exported =false, Icon = "#drawable/ic_launcher", Theme = "#android:style/Theme.Holo.Light", ParentActivity = typeof(MainActivity))]
I am creating an Android application and I'm currently trying to implement user authentication using Firebase. As far as I can tell, my app is connected to my Firebase server.
I encounter a runtime error when attempting to switch from the SignIn activity to the SignUp activity via a button press. The app crashes and I encounter a runtime error.
So far as I can tell, the runtime error is from the SignUp activity's onCreate() call when I attempt to initialize a FirebaseAuth object with FirebaseAuth.getInstance(). This call fails due to
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process seniordesign.phoneafriend. Make sure to call FirebaseApp.initializeApp(Context).
However, I make this call in my Application class' onCreate() method which I thought would be fine. I added the initalizeApp() call to the SignUp's onCreate() call but no dice. I've looked for others with this issue but have not found anything similar. Thanks for any help.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="seniordesign.phoneafriend">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="seniordesign.phoneafriend.PhoneAFriend">
<activity android:name=".SignIn">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SignUp"></activity>
</application>
</manifest>
PhoneAFriend.java (My Application class)
public class PhoneAFriend extends Application {
public void onCreate(){
super.onCreate();
Firebase.setAndroidContext(this);
FirebaseApp.initializeApp(this);
}
}
SignUp.java
public class SignUp extends AppCompatActivity {
protected Firebase ref;
protected EditText emailText;
protected EditText passText;
protected EditText confirmText;
protected Button button;
protected SignUp thisContext;
protected FirebaseAuth auth;
protected FirebaseAuth.AuthStateListener authListener;
private View.OnClickListener onClickListener;
public static Intent intent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
ref = new Firebase("https://phoneafriend-7fb6b.firebaseio.com");
emailText = (EditText) findViewById(R.id.signup_emailText);
passText = (EditText) findViewById(R.id.signup_passwordText);
confirmText = (EditText) findViewById(R.id.signup_passwordConfirm);
intent = new Intent(this, SignIn.class);
//Tried this already
//FirebaseApp.initializeApp(this);
auth = FirebaseAuth.getInstance();
button = (Button) findViewById(R.id.signup_button);
onClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
createUser(view);
Log.v("SignUp Button" , "Clicked; Attempting to create user");
}
};
button.setOnClickListener(onClickListener);
authListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged( FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d("FirebaseAuth", "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d("FirebaseAuth", "onAuthStateChanged:signed_out");
}
// ...
}
};
thisContext = this;
}
#Override
public void onStart(){
super.onStart();
//auth.addAuthStateListener(authListener);
}
#Override
public void onStop(){
super.onStop();
if(authListener != null) {
//auth.removeAuthStateListener(authListener);
}
}
protected void createUser(View view){
String cString = null;
String pString = null;
String eString = emailText.getText().toString();
if(passText.getText() != null && confirmText.getText() != null) {
pString = passText.getText().toString();
cString = confirmText.getText().toString();
Log.v("SignUP: Pass Null check" , "Pass" );
if (emailText.getText() != null && pString.equals(cString) && passText.getText() != null) {
Log.v("SignUP: Sign up check " , "Pass");
auth.createUserWithEmailAndPassword(emailText.getText().toString() , passText.getText().toString())
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.v("createUser complete" , "status: " + task.isSuccessful());
if(task.isSuccessful()){
startActivity(SignUp.intent);
}
}
});
}
}
return;
}
}
I know there's already an accepted answer. However, I ran into the same error message saying: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process (name). Make sure to call FirebaseApp.initializeApp(Context).
I tried several solutions found on SO, and double checking everything, until I finally found that the package name defined in the Firebase Console didn't match the package name defined in my manifest file.
Try go to your Firebase Console -> Project settings -> check if package names matches.
Hope it may help some :)
Just as qbix stated, you much use the API calls from whichever version you are going to use. If possible, you should use the newer API because it will definitely be supported much further into the future.
See the docs here:
https://firebase.google.com/docs/database/android/start/
Remove:
Firebase.setAndroidContext(this);
FirebaseApp.initializeApp(this);
And put:
FirebaseDatabase database = FirebaseDatabase.getInstance();
If qbix puts his comment into an answer, you should accept his rather than mine seeing has how he beat me by a few minutes.
Also:
If you are using the old firebase and need help switching, this guide is spot on and will help you with the switch. It's a fairly simple switch.
https://firebase.google.com/support/guides/firebase-android
I encountered this problem after I deleted and re-cloned my app and forgot to include the google-services.json inside the app module. After I re-added it, the problem went away. Nevertheless, you should init the context inside your custom Application class:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
FirebaseApp.initializeApp(this)
}
}
<manifest
package="your.app">
<application
android:name=".MyApplication"
It is easier to use the Firebase wizard that is included in Android Studio: it adds all the dependencies in the gradle files, creates the firebase project if needed, connects the app with the project, etc.
In Android Studio open menu Tools / Firebase and follow the instructions.
Then FirebaseApp.initializeApp() will return a valid value.
First check up should be the Firebase documentation and the tools from
Android Studio -> Tools -> Firebase -> Cloud Messaging.
Even if you have done that before.
See this, that and that.
Again, even if you already done that before as firebase versions tend to require an up to date configuration JSON.
After much frustration, enabling Internet Permissions fixed this issue for me.
Upgrading classpath 'com.google.gms:google-services:4.1.0' to classpath 'com.google.gms:google-services:4.2.0' in the project Gradle worked for me.
Update 2019 : If you update your Firebase dependencies to latest then you should update Google play services as well.
During the writing of this answer I had updated all my Firebase libs to 17.0.+ but my Google play service was still pointing at 4.1.0.
Updating play service version to 4.3.0(Latest) fixed it for me.
I am a fairly new to android development, and I don't understant how the main class works on Android Studio.
I'm trying to make my app have the Crashlytics and Parse services but I'm not sure where to put them. Currently I have the code on the OnCreate method in the Login Class:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
Parse.initialize(this, "CODE", "CODE");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
But I heard that this code should go on the Application Class... That's because the Application Class is always started and its basically the main Class for the app... I am not sure about this, please correct me if I'm wrong.
If that's the case, how can I access the Application Class and where should I put the code?
Just create a class which should extends the Application , Using this you can initialize the parse installation
public class DemoClass extends Application {
#Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
Parse.initialize(this, "CODE", "CODE");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Copy this above code
I am trying to get basic reporting using ACRA in Android Studio in my test app (Lollipop).
So far, I have implemented following:
added dependancy in gradle
compile 'ch.acra:acra:4.6.2'
added MyApplication which extends Application and added ReportsCrashes annotation to it:
#ReportsCrashes(
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);
}
}
(BTW, sorry for code formatting above, but StackOverflow refused to format it properly for some reason)
This is based on ACRA documentation provided in github https://github.com/ACRA/acra/wiki/BasicSetup
added application name and INTERNET permission in AndroidManifest
<!-- 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>
My main activity has just one button, when clicked, it will crash app when it attempts to do division by zero
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,
The type of notification you should select as
mode = ReportingInteractionMode.TOAST,
//Available : Dialog,Notification,Toast and Silent
resToastText = R.string.crash_text_toast
Here is the sample report parameter what i have used in my app.
#ReportsCrashes(
formUri="",
formUriBasicAuthLogin = "CloundantAuthLogin",
formUriBasicAuthPassword = "CloundantAuthKeyPassword",
reportType = org.acra.sender.HttpSender.Type.JSON,
httpMethod = org.acra.sender.HttpSender.Method.PUT,
customReportContent = { ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL,ReportField.DEVICE_FEATURES,
ReportField.USER_APP_START_DATE,ReportField.USER_CRASH_DATE,ReportField.TOTAL_MEM_SIZE,ReportField.USER_COMMENT,
ReportField.THREAD_DETAILS, ReportField.STACK_TRACE },
mode = ReportingInteractionMode.DIALOG,
includeDropBoxSystemTags = true,
resToastText = R.string.crash_toast_text, // optional, displayed as soon as the crash occurs, before collecting data which can take a few seconds
resDialogText = R.string.crash_dialog_text,
resDialogIcon = android.R.drawable.ic_dialog_info, //optional. default is a warning sign
resDialogTitle = R.string.crash_dialog_title, // optional. default is your application name
resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. when defined, adds a user text field input with this text resource as a label
resDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast message when the user accepts to send a report.
)
Library used : acra-4.6.2
The best tutorial till date available here : http://www.toptal.com/android/automated-android-crash-reports-with-acra-and-cloudant
I'm just new to android development & I'm facing the problem
I grabbed listview from php/json (mysql output) into android device & its working fine.
For notifications I searched a lot and found GCM is good but bit complicated for me as a started.
I got some easy thing done with Parse Notifications (www.parse.com)
But the problem is, when i put Parse initialize lines in my listview code, the app crashes on pushing notification
here is code for my listview
ListView Code
I also tried to put Parse code in service, but still on receiving notification application crashes
and here is how I put parse lines in listview code
protected void onCreate(Bundle savedInstanceState) {
Parse.initialize(this, "ctMEM5bnp9OBIgiewrsxewq2IGVGt5NEdH7zaD4TCAd", "zX9pmbsadfsdacwezzC18XDXE16O1j0rdlOfCHzbdayS");
PushService.setDefaultPushCallback(this, MainActivity.class);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView1);
accessWebService();
}
Please can someone bing these two lines with my listview in manner they won't crash
Parse.initialize(this, "ctMEM5bnp9OBIgiewrsxewq2IGVGt5NEdH7zaD4TCAd", "zX9pmbsadfsdacwezzC18XDXE16O1j0rdlOfCHzbdayS");
PushService.setDefaultPushCallback(this, MainActivity.class);
You should create separate class Application that extends Application and put it in manifest
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class Application extends android.app.Application {
public Application() {
}
#Override
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, "YOUR_APP_ID", "YOUR_CLIENT_KEY");
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, MainActivity.class);
}
}
Manifiest:
<application android:name="com.parse.tutorials.pushnotifications.Application"
See this complete example: Github