Android, unable to get current location using Parse SDK, always times out - android

ParseGeoPoint.getCurrentLocationInBackground(10000, new LocationCallback() {
#Override
public void done(ParseGeoPoint geoPoint, ParseException e) {
if (e!=null)
Print("location not found " + e.getLocalizedMessage());
else
{
Print("location found ");
}
}
});
I have added the required permissions in the manifest.
I have also asked this question here Parse SDK unable to fetch location in background, always time out exception
Thanks

Finally I had to use the default Android apis for getting the user's current location.
Did not find any other solution on how to get the user's location from Parse. Looks like there is no way to it on Parse directly.

Related

Microsoft Face API (Android)- Add Person to Person Group

I know that this may seem to be a rather broad question, but I have been unable to figure out how to create a Person in a Person Group using the Microsoft Face API in Android Studio.
I have tried the following code to make a CreatePersonResult object in Android:
try {
CreatePersonResult person1 = faceServiceClient.createPerson(personGroupId, "Bob", "My Friends");
Toast.makeText(getApplicationContext(), "Created Person called Bob", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Creation failed: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
The above code outputs: "Creation failed: null" which means that the Exception was null for some reason.
In Visual Studio, to create a Person I simply have to do the following:
CreatePersonResult person1 = await faceServiceClient.CreatePersonAsync(personGroupId, "Bob");
Does anyone know how I can create the Person in a Person Group in Android? I have been unable to figure out how to do this in Android, but found plenty of tutorials for Visual Studio.

“Error getting Mms Carrier values” when querying Android Telephony.Carriers public class

I am having trouble obtaining the "server", "mms_proxy", and "mms_port". I haven't found anything official anywhere from Google about why this is? I would assume if this is something I cannot do then that would be stated by Google.
The Android developer website shows the Telephony.Carriers class and all that is available but says nothing about restrictions of any kind so at this point I believe it is fair to assume I can access these rather than have to ask the user to find the APN values manually which will make many people give up instantly and not use my App.
Can we please try to find an official answer as to what is going on here, I have attempted to get this information in many ways all leading to very confusing errors that seemingly cannot be explained.
I am running Android 6.01 on the device ZTE Axon 7. The lowest api that my App will allow is api_21 and the Telephony.Carriers class in available from api_19 and up.
I have declared all then necessary permission in the Manifest file and since I am currently testing on sdk "M" (Android 6), I have also acquired the permissions explicitly at Runtime from the user.
This is the code inside my Activity that I run and receive a an error stating "Error getting Mms Carrier values"...this is the whole problem and where I have become stuck.
ContentResolver contentResolver = getContentResolver();
int index_ID;
final String[] PROJECT =
{
Telephony.Carriers.TYPE,
Telephony.Carriers.MMSC,
Telephony.Carriers.MMSPROXY,
Telephony.Carriers.MMSPORT,
};
grantMyUriPermission(activity, Telephony.Carriers.CONTENT_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
grantMyUriPermission(activity, Telephony.Carriers.CONTENT_URI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Cursor carriers_cursor = SqliteWrapper.query(activity, contentResolver,
Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), PROJECT, null, null, null);
if (carriers_cursor != null)
{
/*This crap below isn't needed for this situation but helps avoid ERROR*/
index_ID = carriers_cursor.getColumnIndex(Telephony.Carriers._ID);
//--------------------------------------------------------------------------------------
if (index_ID < 0 || !carriers_cursor.moveToFirst())
{
Log.i(TAG, "Error getting Mms Carrier values");
carriers_cursor.close();
return;
}
//--------------------------------------------------------------------------------------
do
{
//Confirm cursor has value assigned to it
Log.i(TAG, "cursor: "+ carriers_cursor);
//Get the available columns names
for (String item : carriers_cursor.getColumnNames())
{
//Name of each column available with Cursor
Log.i(TAG, "item: " + item);
//Attempt to get String value for each available column
try
{
//Use the name of the column, to get the index, to get the String value
Log.i(TAG, "getString(): " + carriers_cursor.getString(carriers_cursor.getColumnIndex(item)));
}
catch (Exception e)
{
Log.i(TAG, "Exception: " + e);
}
}
}
while (carriers_cursor.moveToNext());
carriers_cursor.close();
}
The Log output is:
I/SmsReceiveIntentService: Running grantMyUriPermission()
I/SmsReceiveIntentService: Running grantMyUriPermission()
I/NewConversationActivity: Error getting Mms Carrier values
And that's it! Nothing else to go on...?

Android: Parse Server save Error 111: This is an invalid Polygon

I'm trying to save a GeoPolygon into my Parse server using an android app but I keep getting an:
error 111: this is not a valid polygon
this is my code:
//create the parse object
ParseObject obj = new ParseObject("SomeClass");
List<ParseGeoPoint> geoPoints = new ArrayList<ParseGeoPoint>();
geoPoints.add(new ParseGeoPoint(1.468074, 110.429638));
geoPoints.add(new ParseGeoPoint(1.468075, 110.429287));
geoPoints.add(new ParseGeoPoint(1.467376, 110.429681));
geoPoints.add(new ParseGeoPoint(1.467373, 110.429283));
ParsePolygon geoPolygon = new ParsePolygon(geoPoints);
obj.put("Boundaries", geoPolygon);
obj.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(getContext(), "Geo Polygon save complete.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), "Geo Polygon save failed. error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
I followed the Docs for geopolygons here:
http://docs.parseplatform.org/android/guide/#parsepolygon
and somehow, even when I copy pasted the code provided in the docs, it doesnt work.
Any suggestions/ solutions are most welcomed.
I believe not many people may see this but I'll post my solution to this anyway.
The issue was solved after I updated the version of my Parse Server. I didn't note which version I updated the Parse Server from but my current Parse Server is now v2.7.1 .
Previous/ older version of Parse Server does not support geo-Polygons.

com.parse.ParseException: Clients aren't allowed to perform the find operation on the installation collection

I am new to parse ,i am able to store data to its database but whenever i try to retrieve some information like object-id from database i usually get the above mentioned error.Query which i am using to retrieve the object-id corresponding to the given Friend-id.
ParseQuery<ParseObject> query = ParseQuery.getQuery("_Installation");
query.whereEqualTo("FriendId", FrndTextString);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> results, ParseException e) {
if (e == null) {
for (ParseObject x : results) {
String Objectid = x.getString("objectId");
objectidEditText.setText(Objectid);
}
} else {
Toast.makeText(getApplicationContext(),
"Error in retreving Data", Toast.LENGTH_LONG)
.show();
}
}
});
Please help me in solving this issue as I googled a lot but haven’t found anything good solution.Any help will be appreciated.
Thanks.
The _Installation class is an internal class from Parse. The exception occurs because you are trying to access data that is protected by a specific user with specifc ParseACL .
Documentation from Parse:
Every Parse application installed on a device registered for push notifications has an associated Installation object. The Installation object is where you store all the data needed to target push notifications. For example, in a baseball app, you could store the teams a user is interested in to send updates about their performance. Saving the Installation object is also required for tracking push-related app open events.
In Android, Installation objects are available through the ParseInstallation class, a subclass of ParseObject. It uses the same API for storing and retrieving data. To access the current Installation object from your Android app, use the ParseInstallation.getCurrentInstallation() method. The first time you save a ParseInstallation, Parse will add it to your Installation class and it will be available for targeting push notifications.
Try to use another Class, like "Ranking". Ex:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Ranking");
query.whereEqualTo("FriendId", FrndTextString);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> results, ParseException e) {
if (e == null) {
for (ParseObject x : results) {
String Objectid = x.getString("objectId");
objectidEditText.setText(Objectid);
}
} else {
Toast.makeText(getApplicationContext(),
"Error in retreving Data", Toast.LENGTH_LONG)
.show();
}
}
});
You have to pay attention to setup ParseACL correctly for each user and Class, if you want to find public information of others users. At least, all user have to be "Public Read" for data that you want.
Before saving any data in Parse, you have to setup the environment with this tutorial. After, you have to Create the ParseUser and login with it. Parse has an automatic way to create an user, just calling:
ParseUser.enableAutomaticUser();
ParseUser.getCurrentUser().increment("RunCount");
ParseUser.getCurrentUser().saveInBackground();
To save any data in Parse, you can use:
ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground();
Parse Server will automatically create the new class "GameScore", if is not exist. And will create all column, like "score", "playerNAme" and "cheatMode" if it not exist.
To go through with Parse, please read API Doc, it is so helpful.
The Installation class can't be queried like that. Use ParseInstallation.getCurrentInstallation(); instead.
for example,
ParseInstallation.getCurrentInstallation().getString("FriendId");

How to tell the if the City is incorrect in OpenWeatherMap api and in android

I am creating an app which will tell the weather condition of a city using the OpenWeatherMap.org api. In this app I let user to write a city name and the data will be fetched from the web. But what if the user entered wrong city.
For example if a user entered Lomdon instead of London.
What should I do in that case. The Api I am using is
"http://api.openweathermap.org/data/2.5/weather?q="+city name
Thanks in advance for the help, I am new to android development.
If the city is incorrect your API returns an error message. You can check it like this:
"http://api.openweathermap.org/data/2.5/weather?q=Lomdon"
try {
String msg = jsonObject.getString("message");
if (msg.equalsIgnoreCase("Error: Not found city")) {
Log.e("TAG", "City not found");
} else {
// Use the data
}
} catch (JSONException e) {
e.printStackTrace();
}
The reason I didn't use cod which looks like the return code, is that if the city is found cod is an int and if it's not found it's a string. Kind of misleading to design the JSON like that.

Categories

Resources