Moving on from my original question below:
Android Sending an email using a list of email addresses
I have tried to populate the email address line by using a string. When writing the email the message section is populated with the answer given by clicking on a spinner, the code for this is shown as "%1$s". So if I have a spinner that has 4 different countries in the string for the main email I put:
Country: %1$s
And it will show in the final email to be sent as:
Country: UK
For example.
When I put this string into the email Address instead of it originally looking like:
home%1$s#gmail.com
And coming out in the final email as:
homeUK#gmail.com
It stays as home%1$s#gmail.com!
Is there a reason for this? Is it something that cannot be added to the address line?
I have attached my code below and would very much appreciate someones help. I have been pulling my hair out with this one. The rest of the app is complete!
Main Activity
public void sendFeedbackMessage(String subject, String message) {
Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { getResources().getString(R.string.emailaddress_format) };
String bEmailList[] = { ("country#gmail.com") };
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
messageIntent.putExtra(Intent.EXTRA_CC, bEmailList);
//email.putExtra(Intent.EXTRA_BCC, new String[]{to});
messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
messageIntent.setType("plain/text");
messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(messageIntent);
}
}
And the relevant String
<string
name="emailaddress_format">country%1$s#gmail.com</string>
If any more code is needed to see what I am trying to do then please let me know and I will add it. I didnt want to overload everyone with the whole code and then try and explain where I am struggling.
Hopefully someone can help me and i'm making sense.
Many Thanks
Not sure on the exact answer to the particular problem you're having, but an easier way to accomplish what it seems like you're trying to accomplish would be:
Spinner yourSpinner = (Spinner)findViewById(R.id.yourSpinner);
String country = yourSpinner.getSelectedItem().toString();
String aEmailList[] = { "country" + country + "#gmail.com" };
This will get the country the person has selected from the spinner and convert it to a String, which you can then place in the EXTRA_EMAIL as you're doing already.
Related
I want to ask. I got a string json response like this
"Bank Danamon|Reksa Dana Insight Money Syariah"
And i want to change that string to like this in Android setText
Bank Danamon
Reksa Dana Insight Money Syariah
This is the code when i set the response
txvSettlementName.setText(itemSettlement.getAccountName());
Is there a way to do that?
Thanks
You have to split the string like
String str = "Bank Danamon|Reksa Dana Insight Money Syariah";
String[] separated = str.split("|");
separated[0]; // this will contain "Bank Danamon"
separated[1]; // this will contain " Reksa Dana Insight Money Syariah"
String accountName = itemSettlement.getAccountName();
accountName = accountName.replace("|","\n");
txvSettlementName.setText(accountName);
This code will directly replace the character | with line break \n which you can directly set to TextView
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);
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);
}
I have a ArrayAdapter the places JSON strings into a list view. The problem is when it places the strings into the textview it leaves brackets and quotation marks. For example, if the string contained the name Bob. The string would show up in the ListView as ["Bob"]. How do I remove the brackets and quotation marks?
Here is what I use to get the JSON strings,
String username = json2.getString(KEY_USERNAME);
String number = json2.getString(KEY_NUMBER);
String content = json2.getString(KEY_COMMENT);
tempList2.add (new Item (username, number, content));
customAdapter.addAll(tempList2);
You can use a simple replace:
String bob = "[\"Bob\"]";
bob = bob.replace("[", "").replace("\"", "").replace("]", "");
Log.i("Test", bob);
This will now just print Bob
As an addon to Phil's answer, the end quote (in my chrome browser) did not get removed. I fixed it by using .replace("\"", "") again at the end.
I am creating an android app wherein i want to add Twitter share button , on clicking the Twitter button will share something (Title + url) on twitter. I’m almost there, but I have a problem with the link. When I give two parameters with "&", it won’t work. Please let me know if anyone has a suitable answer which i can implement. Answers will be really appreciated.
//Full URL: http://www.mywebsite.com/index.php?option=com_content&catid=40&id=12546&view=article**
String title = "Hello title";
String catid = "40";
String id = "12546";
Uri.Builder b = Uri.parse("http://www.mywebsite.com/").buildUpon();
b.path("index.php");
b.appendQueryParameter("option=com_content&catid", catid);
b.appendQueryParameter("&id", id);
b.appendQueryParameter("&view=article", null);
b.build();
String url = b.build().toString();
String tweetUrl = "https://twitter.com/intent/tweet?text=" + title + "&url=" + url;
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
Output: => “http://www.mywebsite.com/index.php?option=com_content&catid=40”
but the => “&id=12546&view=article” is missing.
You should not provide the ampersand (&) inside the first parameter of the "appendQueryParameter", it will be added for you automatically. Use it as:
b.appendQueryParameter("id", id); // instead of ("*&*id", id);
b.appendQueryParameter("view=article", null); // instead of ("*&*view=article", null);
And the output is going to be the one you expect
https://twitter.com/intent/tweet?text=Hello title&url=http://www.mywebsite.com/index.php?option%3Dcom_content%26catid=40&id=12546&view%3Darticle=null
See here an example of usage.