Recently I have read about the "Create and monitor geofences" section at android developers official website and I found I can't use this section of code:
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Actually my android studio doesn't accept GeofenceErrorMessages class and I can't import with ALT+ENTER shortcut because the android studio doesn't recognize this class at all.
I managed to solve the problem with this code but I really want to know what happened with GeofenceErrorMessages class:
String errorMessage = GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode());
For GeofenceStatusCodes I used this import:
import com.google.android.gms.location.GeofenceStatusCodes;
QUESTION:
Do I need to import something in a project or GeofenceErrorMessages class is maybe deprecated?
I'm using the android studio 3.5.1 version with the newest update.
I ANSWERED ON THIS QUESTION BY MYSELF BECAUSE I THINK MANY DEVELOPER BEGINNERS WIIL SOMETIMES GET STUCK ON SILLY PROBLEMS LIKE THIS ONE.
I just have returned to this section and realized how silly I am.
GeofenceErrorMessages is not a predefined class provided by an android library it's actually class what you need to create by yourself and you can call it whatever you want.
I was confused because it is presented at official android developer website.
Here is an example code with GeofenceErrorMessages class (you can call it Stupid class if you want):
import android.content.Context;
import com.google.android.gms.location.GeofenceStatusCodes;
public class GeofenceErrorMessages {
public static String getErrorCode(Context context, int errorCode) {
switch (errorCode) {
case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE:
return "geofence_not_available";
case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES:
return "geofence_too_many_geofences";
case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS:
return "geofence_too_many_pending_intents";
default:
return "unknown_geofence_error";
}
}
}
You can see here GeofenceStatusCodes class is a predefined class from the android library and I used it to sort different types of geofence status.
Related
I've tried to hide app from launcher by adding and changing codes form the app source but failed every time.
Is it possible to hide a specific app from the launcher by editing Launcher3 source code? btw I'm working with AOSP build and want to integrate a 3rd party Open Source app into Settings, so that it can only be opened from Settings.
Looking through the original Launcher3 source code, you will find AppFilter file under /src/com/android/launcher3. From the file name itself, we know it’s a class to filter applications. There is a method called shouldShowApp, as its name suggest, is to consider if an application is needed to show.
Following this, AllAppsList.java uses this method in the add method. Clearly, when mAppFilter.shouldShowApp return false, it will return directly, making the applications to exclude from the application list, which will not be displayed.
Thus,
The easiest way is by simply change Line the line in AppFilter.java to be return !"com.google.android.gm".equals(app.getPackageName());, where this snippet of code will make sure that the package “com.google.android.gm” (Gmail) to be excluded from showing up in Launcher.
package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context;
public class AppFilter {
public static AppFilter newInstance(Context context) {
return Utilities.getOverrideObject(AppFilter.class, context,
R.string.app_filter_class);
}
public boolean shouldShowApp(ComponentName app) {
return !"com.google.android.gm".equals(app.getPackageName());
}
}
Hope this help.
I am trying to follow this tutorial for Retrofit2 Getting Started and Create an Android Client.
The imports are fine
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
and I can follow the tutorial fine except for one thing. I am trying to create the GitHubService Interface and I run into two problems: The Call<V> says that it doesn't take any type parameters and I am also unsure where to put the Contributor class since it's according to the tutorial only declared as static, does that mean it's nested somewhere?
import okhttp3.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface GitHubClient {
#GET("/repos/{owner}/{repo}/contributors")
Call<List<Contributor>> contributors(
#Path("owner") String owner,
#Path("repo") String repo
);
}
static class Contributor {
String login;
int contributions;
}
I have the Contributor class in a separate file and have it as public.
Also, the Call class does not import automatically in Android Studio, I have to select it manually, but it's the only Call I got (except for Androids phone api)
Please help me with why I get this errors, from what I can see there is no one around with the same thing so I am missing something fundamental.
Accordingly to the compile time error you are getting you did import Call from the wrong package. Please, check your import and be sure that you have
import retrofit2.Call;
everything Retrofit related import should be from the package retrofit2.
On the other hand
Call contributors(
it can't guess what you want to return. A Contributor ? a List<Contributor> maybe? E.g.
public interface GitHubClient {
#GET("/repos/{owner}/{repo}/contributors")
Call<List<Contributor>> contributors(
#Path("owner") String owner,
#Path("repo") String repo
);
}
I am using Play Framework 1.2.5, and trying to use DateTime from Joda Time instead of the usual java.util.Date. I am trying to implement a format method for use in my views.
The Play documentation says I can create my own custom java extensions for use in templates, but it doesn't seem to be working for me. I have followed the example in the docs to no avail.
My custom extension:
package ext;
import org.joda.time.DateTime;
import play.templates.JavaExtensions;
public class DateTimeExtensions extends JavaExtensions {
public static String format(DateTime datetime, String format) {
return datetime==null ? "" : datetime.toString(format);
}
}
My template code:
${subProject?.startDate?.format('yyyy-MM-dd')}
And the error I am receiving:
Exception raised was MissingMethodException : No signature of method: org.joda.time.DateTime.format() is applicable for argument types: (java.lang.String) values: [yyyy-MM-dd]
It looks like Play isn't detecting my custom extension as the documentation says it should. Does anyone have any suggestions on how to make this work?
Your extension class looks good to me. The documentation states that you have to restart your application for the extension to become active. If that doesn't work, try running play clean. Doing so deletes temporary files, including cached bytecode, which will hopefully resolve your issue.
I think I have misunderstood something about the Play 2 framework.
In my Application Controller I fetch a Company object from the DB
and I would like to make some operations on it in my view.
companyView.scala.html:
#(company: Company)
#main("Welcome to Play 2.0") {
<h1>#{company.name}</h1>
}
Application Controller:
package controllers;
import models.Company;
import play.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public static Result company(String rest) {
Company company =
Company.find.where().ilike("restfulIdentifier.identifier", rest).findUnique();
return ok(companyView.render(company));
}
}
But return ok(companyView.render(company)); results in compilation error since companyView.render wants a string.
If I look at the forms sample application:
/**
* Handle the form submission.
*/
public static Result submit() {
Form<Contact> filledForm = contactForm.bindFromRequest();
if(filledForm.hasErrors()) {
return badRequest(form.render(filledForm));
} else {
Contact created = filledForm.get();
return ok(summary.render(created));
}
}
There is no problem with rendering an object. I guess that the solution is fairly simple and
that I have missed some crucial part of the documentation. Please explain this to me!
My steps in this case would be as follows:
Change the scala template, we hve to tell the scala templates the our Company belongs to the model class: (but also change to #company.name as suggested by Jordan.
#(company: models.Company)
#main("Welcome to Play 2.0") {
<h1>#company.name</h1>
}
run command play clean
Then run play debug ~run
By executing play debug ~run you will trigger to compile the the play application on each SAVE of one of your project files.
NOTE: The Play templates are basically functions. These functions needs to be compiled and everything used in these functions needs to be declared before use. Just as in regular Java development.
The fact that the your render object wants a string could be the result of:
#(company: Company) could not be resolved to the model Company.
The last compilation had a #(company: String)
Good luck!
I don't know if this will fix your problem or not but it's worth a try. Try removing changing:
#{company.name}
to:
#company.name
I am not that good to understand all the possibility of Java, especially if it's not my code.
So, http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/text/Html.java#Html.fromHtml%28java.lang.String%29 , is it all I need to modify Html.fromHtml() ?
But I don't understand how it's works : Is it a good way to create a new class like Html2 and copy/paste all the code ? When I do that I have some errors that I don't understand :
private static class HtmlParser {
private static final HTMLSchema schema = new HTMLSchema();
}
He tells my Htmlschema cannot be resolved to a type, and to add the class HtmlSchema... but where can i find it ?
And this :
return XmlUtils.convertValueToInt(color, -1);
XmlUtils cannot be resolved.
The rest of the errors have been solved with the help of Eclipse
He tells my Htmlschema cannot be resolved to a type, and to add the class HtmlSchema... but where can i find it ?
import org.ccil.cowan.tagsoup.HTMLSchema;
HTMLSchema is from TagSoup, a JAR used inside of Android's frameworks but not exposed through the Android SDK.
XmlUtils cannot be resolved.
import com.android.internal.util.XmlUtils;
XmlUtils is a class from the Android firmware, not exposed through the Android SDK.