ACTION_CALL Intent getting rid of # at the end of number - android

The below code makes calls within android however, the # at the end of the number is removed and the android calls the number without it, is there a way to specify that android should keep the # at the end of the number cause I need it in this case?
Intent startCall = new Intent(Intent.ACTION_CALL);
Uri uri = Uri.parse("tel:*001203#");
startCall.setData(uri);
startActivity(startCall);
Android Manifest has the below permissions.
<uses-permission android:name="android.permission.CALL_PHONE"/>

Just use this snippet on clicking :
call.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String s = Uri.encode("*001203#");
Intent callIntent = new Intent(Intent.ACTION_DIAL);;
callIntent.setData(Uri.parse("tel:"+s));
startActivity(callIntent);
}
});

String hash = Uri.encode("#");
String ussd = "*" + hash + "001203" + hash;
startActivityForResult(new Intent("android.intent.action.CALL",Uri.parse("tel:" + ussd)), 1);
this is the workaround.

Related

I need to call a phone number from my android app? Which one if efficient from the below

1) I have used linkify html method link
value = ""+number+"";
Linkify.addLinks(t, Linkify.PHONE_NUMBERS);
Html.fromHtml(value);`
2) Clickable Span method
ClickableSpan clickableSpan = new ClickableSpan() {
#Override
public void onClick(View textView) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber.replace(" ", "")));
startActivity(intent);
}
SpannableString spannableString = new SpannableString(stringBuilder);
spannableString.setSpan(clickableSpan, phoneSpanStart, phoneSpanEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
The second approach is best which is using the intent. As it is officially recommended in Android documentation.
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber.replace(" ", "")));
startActivity(intent);
Note:
Places a phone call (requires the CALL_PHONE permission)
<uses-permission android:name="android.permission.CALL_PHONE" />

How to call # from program in android

I want to do this for my school project I want call from my app to show imei number so I want # also to be copied to phone call.But when I am executing the below code only the * is copied to phone call area
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "*#06#"));
startActivity(intent);
in order to call USDD codes you have to use something like this :
String code = "*" + Uri.encode("#") + "06" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + code)));
and don't forget to use the call permission in your manifest :
<uses-permission android:name="android.permission.CALL_PHONE"/>

Android: How to send multiple sms via intent (diff phone no and body)

I'm using following code for sending text message via Intent ( can not ask for permission so smsmanager is not an option)
//Code from this question
// <http://stackoverflow.com/questions/20079047/android-kitkat-4-4-hangouts-cannot-handle-sending-sms-intent>
private void sendsms(String toContact, String text){
Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this);
intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + Uri.encode(toContact)));
intent.putExtra("sms_body", text);
if (defaultSmsPackageName != null) // Can be null in case that there is no default, then the user would be able to choose any app that supports this intent.
{
intent.setPackage(defaultSmsPackageName);
}
}
else
{
intent = new Intent(Intent.ACTION_VIEW);
intent.setType("vnd.android-dir/mms-sms");
intent.putExtra("address", toContact);
intent.putExtra("sms_body", text);
}
this.startActivity(intent);
}
and I'm calling this in a for loop :
for(int i = 0; i<4 ;i++) {
sendsms(phoneNo[i],smsBody[i]);
}
Now the problem is whenever user gets to this line, the void will be called 4 times, but user will only see the last message in the devices default messaging app ready to be sent, but to get to the other ones, user should press back on the device and if not, he/she would never see the other messages.
what I need to be done is using a method like startActivityForResult(); so each time user sends the message he would be redirected to my app, and then my app starts another activity for the next text message.
any idea?
Thanks in advance
First of all you need to create a String with your phones, for that you have to use "; " as separator, but take care with Samsung, in those devices you have to use ", ".
So your code has to be similar to this one:
private void sendSms(String phone1, String phone2){
String separator = "; "
if (Build.MANUFACTURER.toLowerCase().contains("samsung"))
separator = ", "
String phones = phone1 + separator + phone2...
Intent intentSms = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", phones, null));
intentSms.putExtra("sms_body","your text") // Just if you want to add text
startActivity(intentSms);
}

Make USSD call in android

To check the balance first i have to make a call *xxx# and then i get a response with the multiple options to choose from and after i input the particular number i get the balance.
What code can i use for the same in my android app?
Dialing *xxx*x# is giving me error.
Below is my code which works fine for the *xxx# calls:
String encodedHash = Uri.encode("#");
String ussd = "*" + encodedHash + lCallNum + encodedHash;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));
This works for me:
private Uri ussdToCallableUri(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);
}
Then in work code:
Intent callIntent = new Intent(Intent.ACTION_CALL, ussdToCallableUri(yourUSSDCodeHere));
startActivity(callIntent);
Don't forget to add permission it will solve skype problem:P
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
String ussd = "*XXX*X" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));
this works perfect with me. just place the first bunch as it is then encode the # to make it have a complete *XXX*X#. this will definitely be of help
Important thing to remember :
If your are targeting Android Marshmallow (6.0) or higher then you need to request Manifest.permission.CALL_PHONE permission at runtime
Use this code, it works
Intent callIntent = new Intent(Intent.ACTION_CALL);
String ussdCode = "*" + 2 + Uri.encode("#");
callIntent.setData(Uri.parse("tel:" +ussdCode));
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
Add this line in Manifest file too
<uses-permission android:name="android.permission.CALL_PHONE" />
You can use this code. It works for me:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(Uri.parse("tel:" + "*947") + Uri.encode("#")));
startActivity(intent);

Android and dealing with illegal characters in file names

My app can accept various files e.g. images and such but the problem is if the file such as an image contains illegal characters clicking on it will crash the app. How can such behavior be avoided? if possible I'd still like to be able to have the image open. Thanks.
attachedImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
String new_string = imageURI.replaceAll(" ", "%20");
image_uri = Uri.parse("file://" + new_string);
intent.setDataAndType(image_uri, "image/*");
startActivity(intent);
}
});

Categories

Resources