I have synced and resynced the gradle files and built and rebuilt the app many times. I've closed android studio and even restarted the computer. Same error appears.
I've been following the aws tutorial and I'm on step five in the paragraph:
public void runMutation(){
CreateTodoInput createTodoInput = CreateTodoInput.builder().
name("Use AppSync").
description("Realtime and Offline").
build();
mAWSAppSyncClient.mutate(CreateTodoMutation.builder().input(createTodoInput).build())
.enqueue(mutationCallback);
}
private GraphQLCall.Callback<CreateTodoMutation.Data> mutationCallback = new GraphQLCall.Callback<CreateTodoMutation.Data>() {
#Override
public void onResponse(#Nonnull Response<CreateTodoMutation.Data> response) {
Log.i("Results", "Added Todo");
}
#Override
public void onFailure(#Nonnull ApolloException e) {
Log.e("Error", e.toString());
}
};
There is a red underline beneath CreateTodoInput, mutationCallback as well as several others.
Assume you should have GraphQL endpoint and API key after step 4.
Make sure you add classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.9.+' to project/build.gradle and
add the below dependencies in app/build.gradle
apply plugin: 'com.amazonaws.appsync'
dependencies {
//Base SDK
implementation 'com.amazonaws:aws-android-sdk-core:2.15.+'
//AppSync SDK
implementation 'com.amazonaws:aws-android-sdk-appsync:2.8.+'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
}
After step 4 (amplify push), make sure to BUILD your android project and SYNC all the gradle files
Here is the AWS Amplify tutorial page
Related
In my onCreate I call the following function to detect the weather.
private void detectWeather() {
if( !checkLocationPermission() ) {
return;
}
Awareness.getSnapshotClient(this).getWeather()
.addOnSuccessListener(new OnSuccessListener<WeatherResponse>() {
#Override
public void onSuccess(WeatherResponse weatherResponse) {
Weather weather = weatherResponse.getWeather();
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.e("Testing", "Could not get weather: " + e);
}
});
}
In my Manifest file I have added the following meta data and permissions:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<meta-data
android:name="com.google.android.awareness.API_KEY"
android:value="MYKEY"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="MYKEY"/>
And in my Gradle file I've added the following dependencies.
compile 'com.google.android.gms:play-services:+'
compile 'com.google.android.gms:play-services-gcm:+'
compile 'com.google.android.gms:play-services-location:+'
compile 'com.google.android.gms:play-services-awareness:+'
The app launches fine and gets to the awareness API, however it throws the following error in the log: com.google.android.gms.common.api.ApiException: 15. I can't really find the explanation for this error in the documentation nor on Google/Stackoverflow. Am I missing something obvious?
For future readers, weather and place is now deprecated in the Google Awareness API.
An alternative is the NumberEight SDK, which can do a lot more than Awareness (although no regioning is available at the time of writing).
It performs a wide variety of context recognition tasks on both iOS and Android including:
Real-time physical activity detection
Current place categories
Motion detection
Reachability
Local weather
It can also record user context for reports and analysis via the online portal.
To quickly receive weather updates in Java, you would write:
NumberEight ne = new NumberEight();
ne.onWeatherUpdated(
new NumberEight.SubscriptionCallback<NEWeather>() {
#Override
public void onUpdated(#NonNull Glimpse<NEWeather> glimpse) {
Log.d("CurrentWeather", glimpse.getMostProbable().toString());
}
});
Here are some iOS and Android example projects.
Disclosure: I'm one of the developers.
I'm implementing Google Smart Lock into an app, and I was having no trouble with the Api Client building before. In fact, I was finalizing some syntax changes and cleaning up the code (didn't even touch the code that initializes the Api Client), and my app now dies when build() is called on the Api Client builder, due to abstract method zza. Here is the error being displayed:
java.lang.AbstractMethodError: abstract method "com.google.android.gms.common.api.Api$zze com.google.android.gms.common.api.Api$zza.zza(android.content.Context, android.os.Looper, com.google.android.gms.common.internal.zzq, java.lang.Object, com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks, com.google.android.gms.common.api.GoogleApiClient$OnConnectionFailedListener)"
at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
I have no clue why it suddenly started failing, and I couldn't find any changes I made that would have caused this error. Why isn't that abstract method being overridden? It's nested deep inside the library so I don't understand how I could have affected it.
I wrapped the Google Api Client calls in a manager I named CredentialManager. Here is the code I used to initialize the client:
public CredentialManager(ContextProvider contextProvider) {
mContextProvider = contextProvider;
mCredentialsApiClient = new GoogleApiClient.Builder(mContextProvider.getContext())
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
#Override
public void onConnected(#Nullable Bundle bundle) {
Log.i(CredentialManager.TAG, "Api connected");
}
#Override
public void onConnectionSuspended(int i) {
Log.i(CredentialManager.TAG, "Connection suspended with status " + i);
}
})
.enableAutoManage(mContextProvider.getContext(), connectionFailedResult -> {
if (connectionFailedResult.hasResolution()) {
try {
connectionFailedResult.startResolutionForResult(
mContextProvider.getContext(),
CredentialManager.Codes.RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, log error
Log.e(CredentialManager.TAG, "Resolution failed: " + e.getMessage());
}
} else {
//instead of displaying a dialog, just let the user continue and login manually.
Log.e(CredentialManager.TAG, "Connection failed: " + connectionFailedResult.getErrorMessage());
}
})
.addApi(Auth.CREDENTIALS_API)
.build();
}
If you have any insight as to what is causing this error, please let me know. I've scoured the internet for anyone that has seen something like this before, but couldn't find anything.
The issue was that some google play services dependencies had their versions updated and not the play-services-auth dependency used for google smart lock. The apk would compile fine, but crash when the Google Api Client was trying to initialize. The fix was to make all the versions the same, and invalidate cache + restart android studio, recompile, and run.
I want to use the JSONParser codes but when I write the codes some imports are wrong or it's marked by red.What I have to do?
try using the volley library. this will remvoe all your headache of using the JSONParser class to get the json from the url and so on.
Please refer this link for volley:
http://www.androidhive.info/2014/09/android-json-parsing-using-volley/
.. Let me know if this helps ! :)
Have you added the dependency to your project? If not, write this line to your build.gradle file
compile 'org.apache.httpcomponents:httpcore:4.0-beta3'
For Http Client, add this dependency for your project:
compile 'org.apache.httpcomponents:httpclient:4.5.1'
Besides, that library was deprecated. You should use HttpUrlConnection instead.
TIP: If you want to import some library (dependency), just copy that library package(e.g. org.apache.http.HttpEntity) + "dependency" then type to Google :D
Try using Fast Android Networking Library
Add this dependency to your build.gradle (app level)
compile 'com.amitshekhar.android:android-networking:1.0.0'
Add internet permission in manifest
For GET Method
AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}")
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.addHeaders("token", "1234")
.setTag("test")
.setPriority(Priority.LOW)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
#Override
public void onResponse(JSONArray response) {
// do anything with response
}
#Override
public void onError(ANError error) {
// handle error
}
});
For POST method
AndroidNetworking.post("https://fierce-cove-29863.herokuapp.com/createAnUser")
.addBodyParameter("firstname", "Amit")
.addBodyParameter("lastname", "Shekhar")
.setTag("test")
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
#Override
public void onResponse(JSONObject response) {
// do anything with response
}
#Override
public void onError(ANError error) {
// handle error
}
});
documentation here: https://github.com/amitshekhariitbhu/Fast-Android-Networking
While adding JSONParser you may get some errors, kindly do this two step:
For me the path was like: C:\Users\vaidu\Instructable2\app\build.gardle
Add this two things to buildgradle file
android {
useLibrary 'org.apache.http.legacy'}
dependencies{ compile 'com.android.support:appcompat-v7:26.1.0' }
I'm writing an Android application with lots of dependencies and I needed to enable multidex because it exceeds the limit (65536k methods). I followed this guide and able to compile and run the application on my test device. The problem is I'm getting a nullpointerexception in Robospice RequestListener
for every api call that I make. I'm sure that the api is responding. It seems that the app fails to map the response to my pojo class.
Note: It's running fine before I enabled the multidex.
here is the request listener
private class MyRequestListener implements RequestListener<PojoClass> {
#Override
public void onRequestFailure(SpiceException e) {
}
#Override
public void onRequestSuccess(PojoClass pojoClass) {
// pojoClass <---- this is null
}
}
here are my dependencies for rest and mapping
'org.springframework.android:spring-android-rest-template:2.0.0.M1'
'com.octo.android.robospice:robospice-spring-android:1.4.14'
'org.codehaus.jackson:jackson-core-asl:1.9.13'
'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
Any suggestions
I originally had ion-1.3.8.jar in my libs directory in Android Studio, with compile files('libs/ion-1.3.8.jar') in my build.gradle file. I also had (and still have) androidasync-1.3.8.jar in my libs folder and an entry for it in build.gradle.
I want to get rid of the ion jar and instead use a dependency, but when I delete the jar and put compile 'com.koushikdutta.ion:ion:2.+ in my build.gradle file, I get an error ("cannot resolve method get(String...))" on the following line of code in one of my classes: result.getHeaders().get("USER-TOKEN");.
I'm guessing that line of code probably wasn't what it should have been all along, but it did work with Ion 1.3.8. I can't figure out what I should change it to, and though I can probably figure it out with some trial and error, I would like to hear from the community or Koush about this.
Also, Android Studio is warning me that "Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds". Any thoughts about this?
Here's my code:
Ion.with(activity)
.load(url)
.setJsonObjectBody(loginObject)
.asJsonObject()
.withResponse()
.setCallback(new FutureCallback<Response<JsonObject>>() {
#Override
public void onCompleted(Exception e, com.koushikdutta.ion.Response<JsonObject> result) {
String errorText = activity.getString(R.string.unable_to_login);
if (e != null) {
String errorMessage = e.getLocalizedMessage();
Log.e(TAG, errorMessage);
if (errorMessage.contains(activity.getString(R.string.unable_resolve_host))) {
errorText = activity.getString(R.string.no_internet);
}
}
else if (result != null) {
JsonElement reply = result.getResult().get(activity.getString(R.string.user));
if (reply != null) {
errorText = NO_ERROR;
SessionManager.setProfile(result.getResult());
String userToken = result.getHeaders().get(activity.getString(R.string.user_token));
SessionManager.createLoginSession(userToken);
if (SessionManager.isProfileComplete()) {
activity.startActivity(new Intent(activity, NavigationDrawerActivity.class));
}
else {
activity.startActivity(new Intent(activity, ProfileActivity.class));
}
}
else if (result.getResult().getAsJsonArray(activity.getString(R.string.errors)) != null) {
errorText = activity.getString(R.string.login_error);
}
}
else { // There was some other problem logging in
Log.e(TAG, "Unknown login problem");
}
requestCompleted.onRequestCompleted(errorText);
}
});
On version 2.+ of ION the API probably changed.
If you want to use the old API that works with your code, change your dependency to:
compile 'com.koushikdutta.ion:ion:1.3.8'
It will also automatically add the Android Async 1.3.8 dependency for you.
The warning saying that you should avoid the '+' is because that way, gradle will always get the newest version it finds, where some APIs can change and then break your code.
The API changed slightly in 2. One of those was changing the names of a few methods around the ResponseFuture and RawHeaders classes. In your case, getHeaders() was simply renamed to headers().
The transition from 1.x to 2.x is fairly painless, but there are some breaking changes nonetheless.
If you don't want to deal with the breaking changes, and use the latest version of 1.x in gradle, do the following:
compile 'com.koushikdutta.ion:ion:1.+
There are no breaking changes between 1.x versions. Current 1.x version is 1.4.1 I believe.