On clicking the order app in the app that i have created, it calls the submitOrder() method and it is supposed to display the order summary by calling the createOrderSummary() method in gmail .However the gmail app does not open and it displays the message (which is in the else block )that I can’t display the intent.(i am new to android development.)
CheckBox whippedCreamBox = (CheckBox) findViewById(R.id.whipped_cream_check_box);
boolean isWhippedCreamBoxChecked = whippedCreamBox.isChecked();
CheckBox chocolateBox = (CheckBox) findViewById(R.id.chocalate_check_box);
boolean isChocolateBoxChecked = chocolateBox.isChecked();
int price = calculatePrice(quantity, isWhippedCreamBoxChecked, isChocolateBoxChecked);
EditText nameEditText = (EditText) findViewById(R.id.name_edit_text);
Editable userEnteredString = nameEditText.getText();
String priceMessage = createOrderSummary(userEnteredString, price, isWhippedCreamBoxChecked, isChocolateBoxChecked);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SENDTO);
sendIntent.setData(Uri.parse("mailto:ritvikupadhyay2000#gmail.com"));
sendIntent.setType("text/plain");
sendIntent.putExtra(sendIntent.EXTRA_SUBJECT, "Order for the just java app");
sendIntent.putExtra(sendIntent.EXTRA_TEXT, priceMessage);
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
else
{
displayMessage("I can't display the intent");
}
and here is the java code for createOrderSummary()
private String createOrderSummary(Editable userEnteredString, int price, boolean isWhippedCreamBoxChecked, boolean isChocalateBoxChecked) {
String priceMessage = "Name:" + userEnteredString + "\nAdd whipped cream?" + isWhippedCreamBoxChecked + "\nAdd chocalate?" + isChocalateBoxChecked + "\nQuantity:" + quantity + "\nTotal:$" + price + "\nThank you!\n";
return priceMessage;
Try this way, it is from official docs.
And also note to use String array, many claims using String array only works.
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Related
hi guys i am making an app in which when user click on button it will redirect them to phone app of android with *700# entered. but the problem is when i write # in string it doesn't appear in phone app of android.
here is the code:
public void activite (View view) {
String number = "*700#";
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" +number));
startActivity(intent);
}
it works fine except that number sign doesn't come up please help.
Try this method,
private Uri getCallString(String ussd) {
String uriString = "";
if(!ussd.startsWith("tel:"))
uriString += "tel:";
for(char c : ussd.toCharArray()) {
if(c == '#')
uriString += Uri.encode("#");
else
uriString += c;
}
return Uri.parse(uriString);
}
To call it,
String number = "*700#";
Intent intent = new Intent(Intent.ACTION_CALL, getCallString(number));
startActivity(intent);
See this SO thread.
Try out this:
public void activite (View view) {
String encodedHash = Uri.encode("#"); //encode hash here
String number = "*700";
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" +number+encodedHash)); //updated here
startActivity(intent);
}
public void activite (View view) {
String number = "*700";
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + Uri.encode( number + "#")));
startActivity(intent);
}
this is how it works for me. THANK YOU GUYS FOR REPLYING MY QUERY!
Here I'm trying to send image with text on LinkedIn as post as:
Intent linkedinIntent;
String text1 = "...kaLis...";
linkedinIntent = new Intent(Intent.ACTION_SEND);
Uri path = Uri.parse(MediaStore.Images.Media.insertImage(activity.getContentResolver(),
BitmapFactory.decodeResource(activity.getResources(), R.drawable.logo), null, null));
linkedinIntent.putExtra(Intent.EXTRA_STREAM, path);
linkedinIntent.putExtra(Intent.EXTRA_TEXT, text1);
linkedinIntent.setType("image/*");
// linkedinIntent.setType("text/plain");
boolean linkedinAppFound = false;
List<ResolveInfo> matches2 = activity.getPackageManager()
.queryIntentActivities(linkedinIntent, 0);
for (ResolveInfo info : matches2) {
if (info.activityInfo.packageName.toLowerCase().startsWith(
"com.linkedin")) {
linkedinIntent.setPackage(info.activityInfo.packageName);
linkedinAppFound = true;
break;
}
}
if (linkedinAppFound) {
activity.startActivity(linkedinIntent);
} else {
Toast.makeText(activity, "LinkedIn app not Insatlled in your mobile", Toast.LENGTH_SHORT).show();
}
But this code is enable to send only a thing at a time.
If I click on the HYPERLINK, I get a dialog with the message that no app was found to handle this link, but I know that my android device has some applications to handle this file, becuase I open this file already by click the file itself. Here the code snippet:
case DragEvent.ACTION_DROP:
final String DATA = event.getClipData().getItemAt(0).getText().toString();
final String RECORDS_DIR = ((ScribeApplication ) getApplication()).RECORDS_DIRECTORY_ABSOLUTE_PATH;
final Spanned HYPERLINK = Html.fromHtml("" + RECORDS_DIR + DATA + "");
editor.setMovementMethod(LinkMovementMethod.getInstance());
if (editor.length() > 0)
{
editor.append("\n");
editor.append(HYPERLINK);
}
else
editor.append(HYPERLINK);
return true;
DATA is the file name e.g. record1.3pg
RECORDS_DIR is the absolute path to the directory with the recording files.
HYPERLINK is the absolute path of a record file.
editor is an instance of Eidttext
As mentioned above, if I navigate to the records directory and click the record file itself I get an app chooser and can select an app to handle this record file. So what I did wrong that I dont get an app chooser by clicking the hyperlink within the edittext but rather an dialog with the failure that no app was found?
Many thanks in advance!
Here is my solution for the issue described by CommonsWare:
public class ClickableIntentURLSpan extends URLSpan
{
private Context context;
private Intent intent;
public ClickableIntentURLSpan(final Context CONTEXT, final String URL, final Intent INTENT)
{
super(URL);
final boolean INPUT_OK = (CONTEXT != null) && (INTENT != null);
if (INPUT_OK)
{
context = CONTEXT;
intent = INTENT;
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
else
throw new IllegalArgumentException("Illegal refer to null.");
}
#Override
public void onClick(final View VIEW)
{
context.startActivity(intent);
}
}
case DragEvent.ACTION_DROP:
final String DATA = event.getClipData().getItemAt(0).getText().toString();
final String RECORDS_DIR = ((ScribeApplication ) getApplication()).RECORDS_DIRECTORY_ABSOLUTE_PATH;
final String ABSOLUTE_URL = "file://" + RECORDS_DIR + '/' + DATA;
final Intent PLAY_RECORD_INTENT = new Intent(Intent.ACTION_VIEW);
final File RECORD_FILE = new File(RECORDS_DIR, DATA);
PLAY_RECORD_INTENT.setDataAndType(Uri.fromFile(RECORD_FILE), "audio/*");
final ClickableIntentURLSpan INTENT_URL = new ClickableIntentURLSpan(getApplicationContext(), ABSOLUTE_URL, PLAY_RECORD_INTENT);
final SpannableString HYPERLINK = new SpannableString(DATA);
HYPERLINK.setSpan(INTENT_URL, 0, DATA.length(), 0);
editor.setMovementMethod(LinkMovementMethod.getInstance());
if (editor.length() > 0)
{
editor.append("\n");
editor.append(HYPERLINK);
}
else
editor.append(HYPERLINK);
return true;
I try to add some hyperlinks in mail body when I create my intent but they don't appears in the previsualisation and mail sent.
Also, I set the mime type with "text/html" and I used EXTRA_TEXT static.
This is my code :
String text = "";
text += "<html><body>";
text += "<a href=\"" + CallAPI.mBaseUrl +
"/uploads/media/default/0001/01/021ffb272477a45c032c178de0160e352134f8dd.png" + "\">" + "test" + "</a>";
text += "</body></html>";
Log.d("FragmentFicheProduit", text);
Utils.openApplication(rootView.getContext(), "com.lotus.sync.traveler", getResources().getString(R.string.information_nom_produit) + " " + produit.getNom_produit(), text, null);
public static void openApplication(final Context context, String packageN, String subject, String text, ArrayList<Contact> contactArrayList) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
if (i != null) {
if (subject != null)
i.putExtra(Intent.EXTRA_SUBJECT, subject);
if (text != null)
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(text));
if (contactArrayList != null) {
String[] tmp = new String[contactArrayList.size()];
for (int y = 0; y < contactArrayList.size(); y++) {
tmp[y] = contactArrayList.get(y).getEmailaddress1();
}
i.putExtra(android.content.Intent.EXTRA_EMAIL, tmp);
}
final PackageManager pm = context.getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(i, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches) {
if (info.activityInfo.packageName.endsWith(".traveler")) best = info;
}
if (best != null)
i.setClassName(best.activityInfo.packageName, best.activityInfo.name);
context.startActivity(i);
} else {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageN)));
} catch (android.content.ActivityNotFoundException anfe) {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + packageN)));
}
}
}
Thanks in advance :)
When I added a button it should take me to skype application to a user (name_here) .. if Skype didn't exist on my mobile, it goes to https://play.google.com/store/apps/details?id=com.skype.raider
The code is
raskypelink.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (uri.contains("https://www.skype.com/" )) {
String name_here = "name_here";
String uri1 = "skype://Page/" + name_here;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri1));
startActivity(intent);
} else {
String skype = "skype";
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider" + skype;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri1));
startActivity(i);
}
}
});
Please help!
For IF
Android Docs - http://developer.skype.com/skype-uris/skype-uri-tutorial-android
For ELSE
Change from
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider" + skype;
to
Remove + skype
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider";