How to send acra report in android when my variable = null - android

I have an application that send me user_email = null when it shouldn't. I don't understant it, and can't reproduce it in local. I would like to use acra reporting to report system state when user_email = null.
I know how to write custom variable:
ACRA.getErrorReporter().putCustomData("myVariable", myVariable);
but I don't know how to generate report if var is null, even if the system doesn't crash ( in my case my null variable does not crash the system)

if ( user_email == null) {
ACRA.getErrorReporter().handleSilentException(null);
}
See https://github.com/ACRA/acra/wiki/AdvancedUsage#wiki-Sending_reports_for_caught_exceptions

Related

NullPointerException with Kotlin List object / GSON

I'm using GSON to parse JSON from a web service. I don't have any issues with this on my test device or in the simulator, but I'm getting NullPointerException crashes in the Pre-Launch Report testing on the Play Console when I try to access one of the List objects.
I've tried checking the object for null before accessing it, but I'm still seeing the crash in the Pre-Launch Reports.
Here's the Hourly data class which contains the List object that's causing the crash:
data class Hourly(
#SerializedName("data") val data: List<Conditions> = listOf(),
#SerializedName("summary") val summary: String = "" //Partly cloudy in the evening
)
Here's where I'm accessing the object (with a bunch of extra checks to make sure the objects aren't null before accessing them):
if (forecastData == null || forecastData?.currently == null || forecastData?.hourly == null || forecastData?.hourly?.data == null)
return
val hourlyData = forecastData?.hourly?.data ?: return
if (forecastData?.hourly != null && forecastData?.hourly?.data != null && hourlyData.count() > 2) {
val nextHour = hourlyData[1]
pressure = nextHour.pressure
}
One other thing to note is that this code was all working fine for the past year, but when I updated the app to API 28 and Kotlin 1.3.50 this crash started happening.
Update
I tried setting pretty much every object in my data model class to nullable, but I'm still getting the crash. Here's the end of the crash log, in case that is helpful:
FATAL EXCEPTION: main
Process: com.xxx.xxxx, PID: 27844
java.lang.NullPointerException: throw with null exception
at com.xxx.xxxx.model.Hourly.getData(Hourly.java:3)
at com.xxx.xxxx.view.UserInterface.updateCurrently(UserInterface.java:38)
I assume based on this that I am supposed to check for null on hourly.data...
I have no idea why, but turning off minifyEnabled and turning on multidexEnabled in my release build settings fixed this bug. Glad I spent 3 whole days on this.

Parse for Android: ParseInstallation.getCurrentInstallation().get(KEY_DEVICE_TOKEN) returns null

Parse for Android: Trying to get a device token in Parse but it keeps returning null. This code was working about 6 months back but lately have noticed this issue. Using the device token to subscribe to Parse later on. It just gets stuck in the while loop.I am using Parse 1.7.1 version. Even if I update the parse will this be the right way to get the device token?
private static final String KEY_DEVICE_TOKEN = "deviceToken";
boolean isTokenReady = false;
while (!isTokenReady) {
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get(KEY_DEVICE_TOKEN);
if (!StringHelper.isNullOrEmpty(deviceToken)) {
isTokenReady = true;
} else {
sleep(1000);
}
}
ParsePush.subscribeInBackground("pushtoken_" + deviceToken);
You can use this, if you are retrieving a String:
ParseInstallation.getQuery().get(objectId).getString(KEY_DEVICE_TOKEN)
If you need to get the objectId from the default installation class:
ParseInstallation.getCurrentInstallation().getObjectId();
I'm using version 1.9.2. Hope this helps!
There's been 11 updates of the Android parse sdk. I would definitely update since there's lots of fixes.
Also, you shouldn't have to block your thread to wait for the device token. Did you forgot to save the installation before trying to get the deviceToken?
Like this:
ParseInstallation.getCurrentInstallation().save();
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get( "deviceToken" );
Lastly, Im not sure why you would use a unique device token as push channels. You can use the deviceToken directly. So I would suggest not to subscribe to any channels and push notifications to selected devices using their deviceTokens.
I spent a lot of time on this problem too...
getInstallationId() seems to work. I use installationId to query installations and now it works OK

AccountManager.getAuthToken never returns

I am trying to get the auth token for Google account, for the same I am using below code:
AccountManager acoountManager = AccountManager.get( getContext( ) );
AccountManagerFuture< Bundle > accountManagerFuture = acoountManager.getAuthToken( account, "android", null, (Activity) ctx, null, null );
Bundle authTokenBundle = accountManagerFuture.getResult( );
It should return the auth token if my app have permission to access Google Account token else show a permission request screen.
My problem is, in some of the devices it never returns. Also I observed that it was working once I do factory reset to the same device. I am not able to understand why its not returning before without factory reset, was it missing any system service?
Please help!!!
I found my answer here,
https://code.google.com/p/android/issues/detail?id=25473
This is a bug in android which is fixed in lollipop.

Error with PushPlugin when the App is in background

I'm trying to implement a push notification app created with Cordava 3.3 using this: https://github.com/phonegap-build/PushPlugin ; Basing me in this tutorial: www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql
But I have 2 basic problems the first is that the notification does not lead if the app is in background or is closed and the second is that the message reaches Undefined when the app is open in the foreground, could help, as far as I was reading may be due the format of the JSON response or parameters sent in the same.
Here is my code not take long:
https://github.com/jedidas/Push
I achieved a solution that is on file with the plugin "GCMIntentService.java" near line 80 is the next instruction
else {
extras.putBoolean("foreground", false);
// Send a notification if there is a message
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
}
}
discover you can change the "price" for what you want, for example change the "price" for "message" and everything was solved milagorsamente, explain:
we have this:
. 1 $ message = array ("deprive" => $ message);
and read when I read it as:
1. E.payload.message
gives us comes as undefined because payload.price.
In this sense, we have to file in the JAVA plugin
if (extras.getString ("message")! = null && extras.getString ("message"). length ()! = 0) {
                     createNotification (context, options);
                 }
if that does not run because it is coming as "price" instead of "message". everything is solved when I change the "price" of SEND_MESSAGE.PHP for "message." thus not even need to modify the JAVA.

Android + App engine: user.getUserID() is null in endpoint

I have an Android application with GAE server. I tried to authenticate the user as described on developers.google.com, I added the user parameter to the endpoint methods etc. I get a User which is not null, but this method getUserId() returns null. It is similar to this, rather old problem:
Function User.getUserId() in Cloud endpoint api returns null for a user object that is not null
But I still don't know how to work around it. How do you handle this error? Have you ever encountered it?
In android client here's what I did (its simplified) :
credentials = GoogleAccountCredential.usingAudience(getApplicationContext(), "server:client_id:" + WEB_CLIENT_ID);
credentials.setSelectedAccountName(accountName);
WarriorEntityEndpoint.Builder endpointBuilder = new WarriorEntityEndpoint.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credentials);
warriorEntityEndpoint = endpointBuilder.build();
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
warriorEntityEndpoint.getWarrior().execute();
} catch (Exception e) {
}
return null;
}
}.execute();
And on GAE:
#Api(name = "warriorEntityEndpoint", namespace = #ApiNamespace(ownerDomain = "szpyt.com", ownerName = "szpyt.com", packagePath = "mmorpg.monsters"),
version = "version1",
scopes = {"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
clientIds = {Constants.ANDROID_CLIENT_ID, Constants.WEB_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public class WarriorEntityEndpoint {
private static final Logger log = Logger.getLogger(WarriorEntityEndpoint.class.getName());
#ApiMethod(name = "getWarrior")
public WarriorEntity getWarrior(User user) throws OAuthRequestException, IOException {
log.log(Level.SEVERE, "this gives correct email: " + user.getEmail());
log.log(Level.SEVERE, "this is null: " + user.getUserId());
I have also another very important question: is this user authenticated, if getMail() gives me correct account, but getUserId() gives null? I read that user object should be null if it was not authenticated but I am not sure any more...
I'm using App engine SDK 1.8.7. I'm testing on a real device and backend deployed to GAE.
I asked the same question a while ago and got an answer. See link:
Function User.getUserId() in Cloud endpoint api returns null for a user object that is not null
The cause is a bug on appengine.
I guess there is no good solution for it right now. I store e-mail as a normal property and remove it from default fetch group, I use long as a primary key (generated by AppEngine) and I query the entity by the e-mail property. I don't like my solution, I'll accept ( and implement :) ) a better one if anyone can provide.
This is a known issue which has been filed with google, I've attached the issue link below.
There are two workarounds (1) save the user and read back from the store, if it refers to a valid account the user id will be populated (this sucks because you pay the saving / loading / deletion cost for each API access that is authenticated even if it is tiny, and obviously some performance cost) and (2) you could use the google+ ID but that is NOT the same as the user id.
This is extremely frustrating and there is currently no ETA as they are working on some fundamental issues with the auth design as far as I understand.
Please, vote for that issue by starring it. You can find all the information here
https://code.google.com/p/googleappengine/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log&groupby=&sort=&id=8848
And here is the current formally approved workaround [(1) above], which you can also find in the link above, but for ease it's here: How can I determine a user_id based on an email address in App Engine?
For workaround (2) mentioned above, you can look at the first link, and go to post #39.

Categories

Resources