I try to use GSM codes to transfer my calls with an android app.
For example, if I call : **21*otherNumber#
All my calls will be transfered on otherNumber.
My code:
Uri transfert = Uri.parse( "tel:**21*" + numero + "#");
Intent intent = new Intent( Intent.ACTION_CALL, transfert );
startActivity(intent);
However, Uri.parse() has for definition:
" A URI reference includes a URI and a fragment, the component of the URI following a '#' "
So, it removes the # but I need it. The GSM code can't works without it.
Somebody would have an idea ?
I don't think you can't dial phone number with extensions, it's a known issue (see this).
According to this thread, you may try to add %23 like Uri.parse( "tel:**21*" + numero + "%23");
You need to send a URI encoded hash to parse it through the URI.
public static final String encodedHash = Uri.encode("#");
It will keep the URI encoded hash and send the USSD message over GSM as you have specified.
Related
I need an Intent to send a file to apps such as messengers (WhatsApp, etc.) and Email clients (Gmail, etc.) at the same time. Gmail however for some reason I don't understand shows the file uri in the recipient field.
My original uri is:
[package_name].debug.generic.tools.GenericFileProvider/external_files/1544617983061.pdf
The recipient end up as: //[package_name].debug.generic.tools.GenericFileProvider/external_files/1544617983061.pdf
Screenshot from Gmail:
Code with some bug:
Uri uri = FileProvider.getUriForFile(fragment.getActivity(), fragment.getActivity().getApplicationContext().getPackageName() + ".generic.tools.GenericFileProvider", externalFile);
Intent intentSend = new Intent(Intent.ACTION_SEND);
intentSend.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intentSend.setDataAndType(uri, "application/pdf");
intentSend.putExtra(Intent.EXTRA_STREAM, uri);
intentSend.putExtra(Intent.EXTRA_SUBJECT, name);
intentSend.putExtra(Intent.EXTRA_EMAIL, new String[]{"test#provider.com"});
try {
fragment.startActivity(Intent.createChooser(intentSend, fragment.getString(R.string.external_file_send_chooser)));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(fragment.getActivity(), R.string.external_file_send_no_activity, Toast.LENGTH_LONG).show();
}
Does anyone understand what is going on? How come my data uri is interpreted as recipient?
The file itself is attached correctly to the Email and WhatsApp also successfully sends the file.
EDIT:
Question has already been answered here:
Content URI passed in EXTRA_STREAM appears to "To:" email field
I'm trying to send a mail along with multiple files attached to it, however I can't get them to be added to the mail.
I proceed like this:
private void SendMail (List<Data> ToSend)
{
var Attachments = new List<Android.Net.Uri>();
Intent i = new Intent (Android.Content.Intent.ActionSendMultiple);
i.SetType ("message/rfc822");
i.PutExtra (Android.Content.Intent.ExtraEmail, new String[]{"try#mail.com"});
i.PutExtra (Android.Content.Intent.ExtraSubject, "Test");
i.PutExtra (Android.Content.Intent.ExtraText, "Test Test...");
foreach (var content in ToSend) {
Java.IO.File myFile = new Java.IO.File(content.attachmentloc);
// attachmentloc is a string containing the absolute path to the file to attach.
var uri = Android.Net.Uri.FromFile(myFile);
Attachments.Add (uri);
}
i.PutParcelableArrayListExtra(Android.Content.Intent.ExtraStream, Attachments.ToArray());
StartActivityForResult(Intent.CreateChooser(i, "Send mail..."), 0);
}
I checked and the path in the string is good.. however the method .Exists (When used on the Java.IO.File in the foreach) returns false. might be the reason why ?
Thanks for the help.
EDIT:
When trying to add a single attachment, it works just fine.
However whenever I call a function that imply there will be more than one attachment, it fails.
Aka:
Intent i = new Intent (Android.Content.Intent.ActionSend);
var uri = Android.Net.Uri.Parse (ex._FileLocation);
i.PutExtra(Intent.ExtraStream, uri);
Works just fine however replacing
Intent i = new Intent (Android.Content.Intent.ActionSend);
By
Intent i = new Intent (Android.Content.Intent.ActionSendMultiple);
Leads to the same fail and so does replacing:
var uri = Android.Net.Uri.Parse (ex._FileLocation);
i.PutExtra(Intent.ExtraStream, uri);
By
var Attachments = new List<Android.Net.Uri> ();
foreach (var ex in ToSend) {
var uri = Android.Net.Uri.Parse (ex._FileLocation);
Attachments.Add (uri);
//o
}
i.PutParcelableArrayListExtra (Android.Content.Intent.ExtraStream, Attachments.ToArray ());
... I'm using the default mail application (not gmail)
I also tried setting the intent type to " * / * " (without spaces) as suggested somewhere else.
Also tried AddFlags (ActivityFlags.GrantReadUriPermission);
As it works with a single attachment, I know the URIs are valid for sure...
I'd really need help.
I personally found no valid answer to this problem.
Only answer I found is a workaround: compress all the file into a single .zip archive and send that archive as the single attachment.
might be, the mail activity has not enough rights to read your file. Try to add myFile.setReadable(true, false) either when creating file, or here before adding to Attachments array.
I am making an application where the user will click on contact us section and it will open the built-in Gmail application and I have the code to pre-populate the subject and message body in the mail.
I want the code to pre-populate the "To: " section where we add the recipient.
That didn't work for me but this did
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?to="+emailaddress+"&subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
Hope this helps someone else out there
In the intent you use to populate the subject and message, add the following:
intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "youremail#domain.com" });
Check the documentation for EXTRA_EMAIL
I am sending an email in action view, it works perfectly fine in gmail , but if the user chooses any other mailing service it replaces spaces with '+'
like in body text is "check out it is a good day"
it displays as "check+out+it+is+a+good+day"
Any idea how to solve this issues
Here is my function for sending email
private void sendToAFriend() {
String subject = "it is a good day ";
String body = "Check out it is a good day";
String uriText =
"mailto:" +
"?subject=" + URLEncoder.encode(subject) +
"&body=" + URLEncoder.encode(body);
Uri uri = Uri.parse(uriText);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email"));
}
Try this code.
Intent intent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
intent.putExtra(Intent.EXTRA_TEXT, "Body of email");
intent.setData(Uri.parse("mailto:default#recipient.com")); // or just "mailto:" for blank
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app.
startActivity(intent);
From the description of the method URLEncoder.encode
java.net.URLEncoder.encode(String s)
Deprecated. use encode(String, String) instead.
Encodes a given string s in a x-www-form-urlencoded string using the specified encoding scheme enc.
All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9') and characters '.', '-', '*', '_' are converted into their hexadecimal value prepended by '%'. For example: '#' -> %23. In addition, spaces are substituted by '+'
Use Uri.encode(String) instead of the URLEncoder, it handles spaces correctly for this use case.
ACTION_VIEW with mailto link is more preferable if you wish to limit the sending options to email only.
Just use without any encode.
"&body=" + body;
it works for me!
I want to start a new hangout conversation with given people, but I can't find any code for it. Is there any easy solution to do this?
I tryed to make skype call, and it worked easyly with an intent.
Here is the skype code:
Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + nickname));
startActivity(sky);
I want something similar to this.
(Or with skype how can I make a conference call? )
There is currently no way to create a Google+ hangout on an android device using an intent or any other API.
This would be a pretty cool feature, though. If you request it, they might add it.
I think I found the solution, it's quite simple, here is the code:
Intent sky = new Intent("android.intent.action.VIEW", Uri.parse("https://talkgadget.google.com/hangouts/extras/talk.google.com/myhangout"));
startActivity(sky);
You just need to give the url of the hangout, but unfortunately google suspended the named hangots, so this url every time changes. :(
public static void sendHangout(Context ctx, String message, String urlShare, String imgPath){
Intent hangouts = new Intent(Intent.ACTION_SEND);
if(!Utilities.isNullorEmpty(imgPath)){
String file = (String)imgPath.subSequence(0, imgPath.lastIndexOf("/") + 1) + message.replace(" ", "").replace(":", "").replace(".", "")
.replace("/", "") + ".jpeg";
Utilities.copyFile(imgPath, file);
hangouts.setType("image/*");
hangouts.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + file));
}
hangouts.setPackage("com.google.android.talk");
hangouts.setType("text/plain");
hangouts.putExtra(Intent.EXTRA_TEXT, message + ": \n" + urlShare);
ctx.startActivity(Intent.createChooser(hangouts, "Hangouts is not installed."));
}
I hope help you.
Intent i = context.getPackageManager().getLaunchIntentForPackage("com.google.android.talk");
context.startActivity(i);