Pair up info gotten from the Places API - android

I am using the Places API and I have encountered that it helps retrieve information such as the place ID, ph# and the like. I am trying to pair up some data based on the getId method to make a sort of lookup on an external data base (I'm thinking about using SQL but not sure yet) as of now, I just want to know how can I make the method to make the lookup of the information in the external database based on the placeId gotten from the API.
Somthing like, displaying in here the string that contains the result of the lookup:
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
final CharSequence phone = place.getPhoneNumber();
final String placeId = place.getId();
(include the retrieved data in here)
String attribution = PlacePicker.getAttributions(data);
if(attribution == null){
attribution = "";
}
Any help will be highly appreciated guys!.

Related

How To Know Country name from device ip address?

I can get the country name from a device using the location of the device's sim, but for a tablet without a sim this won't work. How can I get the country code or country name from the device's ip when it's connected to internet?
Here's a GeoIP library for Android you can use in your project.
It uses an online API to get the country from the IP address.
https://github.com/seventhmoon/GeoIp-android
Here's a snippet on how to use it:
ApiManager apiManager = new ApiManager(Volley.newRequestQueue(context));
apiManager.getGeoIpInfo(new Response.Listener<GeoIpResponseModel>() {
#Override
public void onResponse(GeoIpResponseModel response) {
//This is how you get the information.
//not all attribute are listed
String country = response.getCountry();
String city = response.getCity();
String countryCode = resopnse.getCountryCode();
double latitude = response.getLatitude();
double longtidue = response.getLongitude();
String region = response.getRegion();
String timezone = response.getTimezone();
String isp = response.getIsp();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
String errorMessage = error.toString();
}
});
It depends on how exact you want to be - noting that this technique is not very accurate anyway! There are all sorts of ways of defeating geolocation by IP address.
However, there are websites that you can query with the IP address and it will return a country.
But if you don't want to go online to find out, you will need to take a dump of the current list, encode it in a lookup table, and store it inside your program.
You will not want to store every address - there are 4 billion possible ones - but instead store large ranges. This will reduce the table size considerably.

How can i get few characters from String?

I want to retrieve few characters from string i.e., String data on the basis of first colon (:) used in string . The String data possibilities are,
String data = "smsto:....."
String data = "MECARD:....."
String data = "geo:....."
String data = "tel:....."
String data = "MATMSG:....."
I want to make a generic String lets say,
String type = "characters up to first colon"
So i do not have to create String type for every possibility and i can call intents according to the type
It looks like you want the scheme of a uri. You can use Uri.parse(data).getScheme(). This will return smsto, MECARD, geo, tel etc...
Check out the Developers site: http://developer.android.com/reference/android/net/Uri.html#getScheme()
Note: #Alessandro's method is probably more efficient. I just got that one off the top of my head.
You can use this to get characters up to first ':':
String[] parts = data.split(":");
String beforeColon = parts[0];
// do whatever with beforeColon
But I don't see what your purpose is, which would help giving you a better solution.
You should use the method indexOf - with that you can get the index of a certain char. Then you retrieve the substring starting from that index. For example:
int index = string.indexOf(':');
String substring = string.substring(index + 1);

How to get Text written after "," in MultiAutoCompleteTextView?

I am developing an application that uses MultiAutoCompleteTextView for showing hints in the drop down list.In this application I retrieve the value written in the MultiAutoCompleteTextView by using
multitextview.getText();
and then query this value to server to recieve JSON response which is shown as suggestions in the drop down list.
If a user types Mu and then Selects music from the list and then types box for another suggestion the content in the MultiAutoCompleteTextView becomes Music,box and now the value for querying to the server is Music,box instead of this I want to select only box.
My question is how to retrieve text written after "," in MultiAutoCompleteTextView?
Can this be achieved using getText()?
I solved this issue
String intermediate_text=multitextview.getText().toString();
String final_string=intermediate_text.substring(intermediate_text.lastIndexOf(",")+1);
I'm sure there are several ways to get around this. One way to do it would be:
String textToQuerryServer = null;
String str = multitextview.getText().toString(); // i.e "music, box" or "any, thing, you , want";
Pattern p = Pattern.compile(".*,\\s*(.*)");
Matcher m = p.matcher(str);
if (m.find()) {
textToQuerryServer = m.group(1);
System.out.println("Pattern found: "+ textToQuerryServer);
}else {
textToQuerryServer = str;
System.out.println("No pattern: "+ textToQuerryServer);
}

save data to Parse cloud

I have 3 edit-texts in my activity (Name, mobile number, occupation) and a button (Save). I want to save these three data to Parse-cloud every-time when user clicks on the button.
Then new activity to display with a image in imageview that should be saved with the corresponding mobile number.
Saving data to parse is very simple. In your button click handler you just need to get the 3 values that you are interested in then create the new parse object;
String name = nameEditText.getText().toString();
String mobileNumber = mobileNumberEditText.getText().toString();
String occupation = occupationEditText.getText().toString();
ParseObject dataObject = new ParseObject();
dataObject.put("name", name);
dataObject.put("mobilenumber", mobileNumber);
dataObject.put("occupation", occupation);
dataObject.saveInBackground();
Somewhere in your app you will need to remember to set your application id and key as supplied to you by Parse. I tend to do it in an Application object in the onCreate method;
public void onCreate() {
Parse.initialize(this, "Your Application Id", "Your Client Key");
}
The Parse Object API is very simple to work with I tend to find as there isn't too much to get your head around. If you are completely new to Parse and you haven't already then I would recommend taking a look at their quickstart.

Can I extend Androids Contacts database?

I was wondering is it possible to extend the Android Contacts database?
From here - http://d.android.com/reference/android/provider/ContactsContract.html
It says:
ContactsContract defines an extensible
database of contact-related
information
Extensible would suggest to me that I can add in more data to the contacts application outside the normal values such as Name, number, email, work number, home number etc..
However the examples of this page - http://d.android.com/reference/android/provider/ContactsContract.RawContacts.html only show how to insert the standard values like name and not how to add a new field to a contact.
Furthermore a search on the web does not turn up much information on extending the contacts data.
So I was wondering is it even possible or does the extensible refer to some other part of the contacts?
For example I would like to add in an additional field for contacts that have special privileges within my app so when a user looks at the contacts he or she knows what users they can use my app with.
Is this possible?
You can store custom data in the contacts database. However "when a user looks at the contacts he or she knows what users they can use my app with," may not be possible if you are thinking users will be able to see the custom data you inserted while using the built-in Android Contacts application. You would have to display the custom data in your own application.
The javadocs for the ContactsContract.Data class should provide an explanation, as well as the Contacts article.
To use this you'll need to get a raw contact id by querying the RawContacts.
Here some example code that might help you get started...
private void makePowerful(int rawContactId) {
ContentValues values = new ContentValues();
values.put(Privilege.RAW_CONTACT_ID, rawContactId);
values.put(Privilege.MIMETYPE, Privilege.CONTENT_ITEM_TYPE);
values.put(Privilege.PRIVILEGE_LEVEL, Privilege.TYPE_POWERFUL);
Uri uri = getContentResolver().insert(Data.CONTENT_URI, values);
}
public static final class Privilege implements ContactsContract.DataColumnsWithJoins, ContactsContract.CommonDataKinds.CommonColumns {
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/my_app_privilege";
public static final int TYPE_POWERFUL = 1;
public static final int TYPE_WEAK = 2;
public static final String PRIVILEGE_LEVEL = DATA1;
private Privilege() { }
}

Categories

Resources