I am creating an app and i get an Address from geocoder.So I am getting a string that contains the address.My problem is that I want to put the name in a Textview the number in an Edittext(so the client can edit the number) and the city with the postcode to an other Textview.Any ideas?Thanks.
If there is a particular pattern in the Address you get, you can use String.split() method of Java to extract tokens which can then be used individually to fill particular information. See this example for understanding its working.
The best approach would be to write a Regular expression and group corresponding pieces of information and then getting them back using Matcher class.
This example explains how to get Regular expression's to work.
Related
I making an application in which my requirement is to get the Recently Added or Edited or Deleted Contact in Phonebook. So is there is way to achieve this. Any help will be appreciated.
You need to show what you tried, so that we can write our answers based on your try.
First, make sure you have this:
<uses-permission android:name="android.permission.READ_CONTACTS" />
According to the android docs, you can easily read contacts, and, to get specific selections (which is exactly what you want) you can:
Define a search text expression that retrieves rows for a specific
contact's LOOKUP_KEY and the Data.MIMETYPE of the details you want.
Enclose the MIMETYPE value in single quotes by concatenating a "'"
(single-quote) character to the start and end of the constant;
otherwise, the provider interprets the constant as a variable name
rather than as a string value. You don't need to use a placeholder for
this value, because you're using a constant rather than a
user-supplied value.
Take a look at the different ways to get specific selection keys on contacts, so that you can get exactly what you want.
http://developer.android.com/training/contacts-provider/retrieve-details.html
I am trying to make a performance testing process by using the Jmeter for the mobile chat application. The scenario i am trying is,need to analyze the output during the N number of new user registration process.I am feeding the N user data through "CSV Data Set Config".In that mentioned the variable names as "phone,ime".
For each new user registration process,the application will generate the one time password when calling the API1.The question is,I need to get that generated one time password from the API1 response message for each phone user and need to assign the value to the variable ${code} when calling the API2.
The below are the API & parameters details:
API1:/api/users/registration-sms.html?
1) Name:phone, Value: ${phone}
2) Name:ime, Value: ${ime}
Example :
Request - POST data: phone=917010370002 & ime=e78b56418b55b32c
Response:{"response":{"httpCode":200,"Message":"True","Code":"5858"}}
API2: /api/users/registration-sms-verfy.html?
1) Name:phone, Value:${phone}
2) Name:code, Value:${code}
Note : For this variable ${code},We need to get the data from the API1("Code":"5858") response message for the respective phone(917010370002).
Please provide me the feasible solution to sort out of my requirement.
Thanks in advance.
You can use Regular extractor post processor like,
Assuming your response is like
{"response":{"httpCode":200,"Message":"True","Code":"5858"}}
your regular expression will be like to extract code value but for specifiic phone no you need to modify it a little bit,
"Code"\:"(\d+)"
for occurance detail you can provide which match no. you want.
Refer Regular Expression Exctrator Post Processor
I am getting a kmz-file from a webservice, which I use for geofencing.
The app is responsible to check whether the gps-location of the phone is within the geofence, or not.
I don't really know how the kmz-file will be structured (I am not creating it), but I think the coordinates might look like this:
<coordinates>
-112.2550785337791,36.07954952145647,2357
-112.2549277039738,36.08117083492122,2357
-112.2552505069063,36.08260761307279,2357
-112.2564540158376,36.08395660588506,2357
-112.2644963846444,36.08627897945274,2357
-112.2656969554589,36.08649599090644,2357
</coordinates>
How can I check if the gps-coordinates of my phone are within the geofence (the example above is only a line, it should be a closed area, for example a rectangle)? Right now I can't really think of how to do that.
And what library should be used to access the kmz-files?
First, for geofencing, download the sample from here and read the documentation. And I don;t know about kmz file. But if you can get the string from it(using file reading) and know its structure, then you can easily parse it. If the format is like you mentioned, then you can get the values by following method:
Split the string on coordinates (including <>). You will get a string array. Take the string at index 1.
Split this string on /coordinates (including <>). You will get another string array. Take the string at index 0.
Now split this string on ",". You will get an array of strings again! Now at indexes 0,3,6... are latitudes and at indexes 1,4,7... are longitudes and at indexes 2,5,8... are the third number in the data you mentioned.
In an Android app I've got a couple contacts from my contacts list. They can be either emails, phone numbers, or even other things. I now want to check which type it is and bind specific actions to them.
For example, if it is a type vnd.android.cursor.item/email_v2, I want to send a POST message with just the email field, and if it is a type vnd.android.cursor.item/phone_v2 I want to send a POST message with just the phone field.
Any ideas how I could check this?
I guess the way to go would be using overloading:
You implement multiple methods with different input parameters but the same name, such as:
checkContact(email_v2 email){ do things with email }
checkContact(phone_v2 phone){ do things with phone }
checkContact(String s){do things with random string }
I think you get my point.
If you want a simple if-statement, though:
if (contact instanceof vnd.android.cursor.item/email_v2){ do send }
You could try checking the class constant CONTENT_ITEM_TYPE for your different types, something like:
contact.CONTENT_ITEM_TYPE.equals("vnd.android.cursor.item/email_v2");
I have a working android app using TextView, some formatting (line breaks, rows of dashes) and Linkify to generate a primitive "ListView-like" display with clickable URLs in each "row". I'd like to move up to a real ListView, but I'm just not finding the sample/explanation that I need to take that next step.
I have successfully reproduced the HelloListView sample, starting with the hardcoded string array, and moving to a string array defined in my res/values/strings.xml. I've taken one small step toward my goal by adding my HttpClient code to retrieve a set of data from a service, parse the results into a String Array and feed that into setListAdapter() such that my text and links show up as text-only in ListView items.
I want to move to the next step which is to make each "row" in my ListView launch the browser to the URL contained in the data, either by
(A) clicking anywhere in the row, or
(B) clicking a hyperlink displayed within the row data
For option (A), it appears that I need to have my onItemClick() method issue an intent that launches the browser. That's straightforward, but I don't get how to associate the URL with the item (currently its just one part of the string content for each "row" of text). How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL? Do I need to replace my String Array with an array of custom objects?
For option (B), can I use Linkify? It seems that my string array elements get converted to individual TextViews (inferring from the way the Toast text is generated in the HelloListView sample). Do I have access to that TextView to run Linkify against? Do I need to replace my String Array with a TextView Array and run Linkify myself? Am I completely off base?
Thanks to anyone who can help explain back to me what I'm trying to do, in a way that helps to find my way around the SDK, samples and other helps!
How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL?
Use a regular expression (java.util.regex) to find the URL.
For option (B), can I use Linkify?
Yes.
Do I have access to that TextView to run Linkify against?
Yes. Override getView() in your ArrayAdapter. Chain to the superclass and get your TextView from the result of super.getView().
Even better would be to use Linkify on your strings before putting them in the array in the first place.
Do I need to replace my String Array with a TextView Array and run Linkify myself?
No, and that is really not a good idea. Here is a free excerpt from one of my books that goes into more detail on tailoring the individual rows of a ListView, in case this helps.