Cannot Resolve Symbol "Place.Field" - java

I am trying to migrate new Auto Complete Place Picker I have updated library from "com.google.android.gms:play-services" to new "com.google.android.libraries.places:places-compat:2.0.0" and implemented SupportPlaceAutocompleteFragment.
All works fine however the error I am getting is:
"Place.Field" Cannot resolve symbol 'Field'
Below is my code:
// Initialize the AutocompleteSupportFragment.
SupportPlaceAutocompleteFragment supportPlaceAutocompleteFragment = (SupportPlaceAutocompleteFragment)getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
//List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Specify the types of place data to return.
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
supportPlaceAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
#Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Toast.makeText(MapsActivity.this, "Place: " + place.getName() + ", " + place.getId(), Toast.LENGTH_LONG).show();
Log.i("", "Place: " + place.getName() + ", " + place.getId());
}
#Override
public void onError(Status status) {
}
});
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
Can you help me solve this error:
"Place.Field" Cannot resolve symbol 'Field'

Ensure that you import the correct Place class.
import com.google.android.libraries.places.api.model.Place;
Hope this helps.

The SupportPlaceAutocompleteFragment class is deprecated. Please use the AutocompleteSupportFragment class instead. Refer to Google's migration guide and the Place Autocomplete's guide.
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment supportPlaceAutocompleteFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
//List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Specify the types of place data to return.
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
supportPlaceAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
#Override
public void onPlaceSelected(Place place) {
Toast.makeText(MapsActivity.this, "Place: " + place.getName() + ", " + place.getId(), Toast.LENGTH_LONG).show();
Log.i("", "Place: " + place.getName() + ", " + place.getId());
}
#Override
public void onError(Status status) {
}
});
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
Hope this helps!

Related

How to assign roles with a Discord bot made in Java?

I'm trying to get my Meeseeks bot to assign and remove roles on discord for my personal server. I'm not all too familiar with the special methods and commands, and I've had no luck looking for it!
This is my code right now;
package discord.meeseeksBot;
import discord.meeseeksBot.Ref2;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
public class App extends ListenerAdapter
{
public static void main(String[] args) throws Exception
{
JDA jda = new
JDABuilder(AccountType.BOT).setToken(Ref2.token).buildBlocking();
jda.addEventListener(new App());
}
#Override
public void onMessageReceived(MessageReceivedEvent evt)
{
User objUser = evt.getAuthor();
MessageChannel objMsgCh = evt.getChannel();
Message objMsg = evt.getMessage();
//the prefix to which the bot responds to is "Mr.Meeseeks, "
if(objMsg.getContentRaw().equalsIgnoreCase(Ref2.prefix+"I need
help"))
{
objMsgCh.sendMessage("Hi, " + objUser.getAsMention() + ", " + "
I'm Mr.Meeseeks! Look at me! How can I help?").queue();
objMsgCh.sendMessage("You can tell me to **ADD** you to a role,
or **REMOVE** you from a role!").queue();
}
}
}
I'm working to get the bot to where he'll reply to "Mr.Meeseeks, I need help"
with a list of title roles (these roles serve no hierarchical purpose, nor do they appear separately from online members!) you can choose from, and apply to yourself. I'd also like him to be able to remove yourself from a role.
And example for what I had in mind was a role for gender pronouns, (i.e. "she/her" or "he/him") so that when a profile is clicked on in the server, you'd be able to see what they'd be called.
So you could say, "Mr.Meeseeks, add me to "she/her" pronouns!" and he'd do that for you, or "Mr.Meeseeks, remove me from "she/her" pronouns!".
I can't seem to figure it out for Java.
I am not too familiar with JDA, as Discord4J is better, but I can point you in the right direction.
You want to use regex to test for "Mr", "Meeseeks", "add", and "me" all in the same message. Then you can test for the gender pronouns:
#Override
public void onMessageReceived(MessageReceivedEvent evt) {
User objUser = evt.getAuthor();
MessageChannel objMsgCh = evt.getChannel();
Message objMsg = evt.getMessage();
String content = objMsg.getContentRaw();
Guild guild = evt.getGuild();
//the prefix to which the bot responds to is "Mr.Meeseeks, "
if (objMsg.getContentRaw().equalsIgnoreCase(Ref2.prefix + "I need help")) {
objMsgCh.sendMessage("Hi, " + objUser.getAsMention() + ", " + " I'm Mr.Meeseeks! Look at me! How can I help?").queue();
objMsgCh.sendMessage("You can tell me to **ADD** you to a role, or **REMOVE** you from a role!").queue();
// Test for "Mr", "Meeseeks", "add", and "me".
} else if (content.matches("^(?=.*\\badd\\b)(?=.*\\bme\\b)(?=.*\\bto\\b)(?=.*\\bMr\\b)(?=.*\\bMeeseeks\\b).+")) {
// Test for pronouns (Assuming your roles names are "he/him" and "she/her")
Role group = content.matches("((she)|(her))") ? guild.getRolesByName("she/her", true).get(0) :
content.matches("((he)|(him))") ? guild.getRolesByName("he/him", true).get(0) : null;
if (group == null) {
// Let the user know if they used an invalid pronoun.
objMsgCh.sendMessage("Sorry " + objUser.getAsMention() + ", I can't find that role!").queue();
} else {
// Assign the role.
guild.getController().addRolesToMember​(guild.getMember(objUser), group);
objMsgCh.sendMessage("Added " + objUser.getAsMention() + " to " + group.getName() + "!").queue();
}
}
}

Error with sending PushNotifications with OneSignal android

I am working on a Messaging Android App. Users should be notified with a push notification.
At the time I have this code:
public void notifyUser(String user_id, String message) {
try {
OneSignal.postNotification(new JSONObject("{'contents': {'en':['" + message + "']}, " +
"'include_player_ids': ['" + user_id + "'], " +
"'headings': {'en': 'Tag sub Title HI {{user_name}}'}, " +
"'data': {'openURL': 'https://imgur.com'}," +
"'buttons':[{'id': 'id1', 'text': 'Go to GreenActivity'}, {'id':'id2', 'text': 'Go to MainActivity'}]}"),
new OneSignal.PostNotificationResponseHandler() {
#Override
public void onSuccess(JSONObject response) {
Log.d("LOL", "postNotification Success: " + response.toString());
}
#Override
public void onFailure(JSONObject response) {
Log.d("LOL", "postNotification Failure: " + response.toString());
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
But I get an Error in Log:
D/LOL: postNotification Failure: {"errors":["Notification contents for each language must be a string"]}
I searched threw the Internet but didn't find a solution for my Problem.
I hope you can help me...
Thanks in advance.
I believe the error you're seeing is because you're sending up the message inside an array when it should just be a string.
"{'contents': {'en':['" + message + "']} should be "{'contents': {'en':'" + message + "'} (removed the brackets).

Parse save ParseGeoPoint by objectId fails with "com.parse.ParseRequest$ParseRequestException:"

Following instructions here to save data to an object by objectId thru android app and getting errmsg com.parse.ParseRequest$ParseRequestException: (without anything following semicolon). I have confirmed objectId is as shown in parse dashboard. Can someone please help me figure out what I'm doing incorrectly? Thanks
final String parseRequest = "Request";
final String parseRequestDriverLocation = "driverLocation";
private void saveDriverLocation(String objectId, Location driverLocation) {
Log.i("saveDriverLocation", "objectId=" + objectId + ", driverLocation=" + driverLocation.toString());
ParseGeoPoint locationDriverParse = new ParseGeoPoint(driverLocation.getLatitude(), driverLocation.getLongitude());
ParseObject acceptedRequest = ParseObject.createWithoutData(parseRequest, objectId);
Log.i("saveDriverLocation", "acceptedRequest=" + acceptedRequest.toString() + "\nlocationDriverParse=" + locationDriverParse.toString());
acceptedRequest.put(parseRequestDriverLocation, locationDriverParse);
acceptedRequest.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.i("saveDriverLocation", "driver location saved successfully");
} else {
Log.i("saveDriverLocation", "saving driver location failed... " + e.toString());
}
}
});
}
The logcat:
I/saveDriverLocation: objectId=Ddm73yXhPC, driverLocation=Location[gps 41.677770,-80.385998 acc=20 et=+1d7h59m59s883ms alt=18.0 {Bundle[mParcelledData.dataSize=40]}]
I/saveDriverLocation: acceptedRequest=com.parse.ParseObject#ddeb183
locationDriverParse=ParseGeoPoint[41.677770,-80.385998]
I/saveDriverLocation: saving driver location failed... com.parse.ParseRequest$ParseRequestException:
Apparently a Parse class can only have one ParseGeoPoint column! Here is reference.

How to find senders Bitcoin Address in BitcoinJ after receiving a transaction

So in my app I have the following functionality for receiving bitcoins
kit.wallet().addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
#Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
txtLog.append("-----> coins resceived: " + tx.getHashAsString() + "\n");
txtLog.append("received: " + tx.getValue(wallet) + "\n");
Futures.addCallback(tx.getConfidence().getDepthFuture(1), new FutureCallback<TransactionConfidence>() {
#Override
public void onSuccess(TransactionConfidence result) {
txtLog.append("\nSuccess! Recieved: " + tx.getValue(wallet) + "\n");
//Find address of sender here
}
#Override
public void onFailure(Throwable t) {
throw new RuntimeException(t);
}
});
}
});
This works great, OnSuccess triggers properly once a transaction is confirmed and added to my wallet. txtLog is just a textArea in my java frame which displays some text output for me. What I need to do now is find the address of the sender at this point, can i do this with the Transaction object tx? Any help would be appreciated.
Found the solution! Unfortunately it uses a depreciated method. I just added the following in the appropriate spot.
String address = "";
for (TransactionInput txin : tx.getInputs()){
address = txin.getFromAddress().toString();
}

Get command Google now in my app

I would like to get back results in a variable of type String. The contents of what the user tells his smartphone via Google now that is: "OK google claptrap " I would like to do this so I could get back 'claptrap'. I have already searched but have been unsuccessful. I found how to return my selectable application in Google now like, for example write a note in my app but in this case the person has to say " OK google note at me claptrap " so that I can get back claptrap. It is not proceeding well … I am pretty sure that it is possible because the app "commandr" already makes it for commands as "turn on the torch".
Excuse my bad english.
Thank you in advance Good evening :D
i have create a AccessibilityService for get command google now but i should touch editText for receive the command. Help me please
public class NotificationService extends AccessibilityService {
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
System.out.println("******onAccessibilityEvent*******");
if(event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED || event.getEventType() == AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
System.out.println(" NAME : " + event.getClassName());
System.out.println(" NAME PCK : " + event.getPackageName());
System.out.println(" SOURCE : " + event.getSource());
System.out.println(" TEXT : " + event.getText());
}
}
private String RecupCommandGoogle(AccessibilityEvent mEvent, AccessibilityNodeInfo mSource) {
if (mSource != null & mEvent.getClassName().equals("android.view.View")) {
return String.valueOf(mSource.performAction(AccessibilityNodeInfo.ACTION_SELECT));
}
return null;
}
#Override
protected void onServiceConnected() {
System.out.println("onServiceConnected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_WINDOWS_CHANGED | AccessibilityEvent.TYPE_VIEW_FOCUSED ;
info.packageNames = new String[] {"com.google.android.launcher" , "com.google.android.googlequicksearchbox"};
info.feedbackType = AccessibilityEvent.TYPES_ALL_MASK;
info.notificationTimeout = 100;
setServiceInfo(info);
}
#Override
public void onInterrupt() {
System.out.println("onInterrupt");
}
}

Categories