Get only digits from input and call that number Android - java

Okay, I am creating an android app, I do like to get the number from an input here mostLikelyThingHeard unfortenately my code doesn't work for some reason.
For example when the user says: bel 0612345678
The dialer has to call 0612345678
String one = "bel";
if (mostLikelyThingHeard.contains(one)) {
String numbers = mostLikelyThingHeard.replaceAll("[^0-9]", "");
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:" + numbers));
tts.speak(numbers + " wordt gebeld.",
TextToSpeech.QUEUE_FLUSH, null);
found = true;
}
I also added the right permissions in AndroidManifest.xml, I guess the code is wrong.

You need to get numbers from String like this:
String numbers = mostLikelyThingHeard.replaceAll("[^\\d]", "");
To call that number, you can use ACTION_CALL. ACTION_DIAL will just open a dialer screen with that number. Also, you have initialized intent, but you are missing call to startActivity(intent)
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:" + numbers));
startActivity(call);
Hope this helps.

Can you try this
Intent.ACTION_CALL
and make sure that you are using this before application tag in manifest file
<uses-permission android:name="android.permission.CALL_PHONE" />

You can use regex and delete non-digits.
str = str.replaceAll("\\D+","");

Try this one..
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + yours_numbers_values));
startActivity(intent);

String one = "bel";
String mostLikelyThingHeard="bel 0612345678";
if (mostLikelyThingHeard.contains(one)) {
String numbers = mostLikelyThingHeard.replaceAll("[^0-9]", "");
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+Uri.encode(numbers.trim())));
startActivity(callIntent);
tts.speak(numbers + " wordt gebeld.",
TextToSpeech.QUEUE_FLUSH, null);
found = true;
}
And in Manifest add permission
<uses-permission android:name="android.permission.CALL_PHONE" ></uses-permission>

Related

android, Can I forward phone number data to google duo?

Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.apps.tachyon");
intent.setData(Uri.parse("tel:" + "phonenumber"));
startActivity(intent);
I could not pass the data to 'Google duo' app in the same way
Is there a way?
Try this
Intent duo = new Intent("com.google.android.apps.tachyon.action.CALL");
duo.setData(Uri.parse("tel: " + phoneNumber));
duo.setPackage("com.google.android.apps.tachyon");
startActivity(Intent.createChooser(duo, "Duo is not installed."));

Android code to dial or calll a string containing alphabets *123*abc# instead of numbers (*123#)?

I’m unable to dial or call a string containing alphabets in android.
For Example:
I want to dial a string *123*abcd#.
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+"*123*abcd#")); //This string is not getting dialed
try
{
startActivity(callIntent);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(getApplicationContext(),"yourActivity is not founded",Toast.LENGTH_SHORT).show();
}
String *123*abcd# is not getting dialed or called. Please help to solve the same.
String s = "*123*abcd#";
if ((s.startsWith("*")) && (s.endsWith("#"))) {
callstring = s.substring(0, s.length() - 1);
callstring = callstring + Uri.encode("#");
}
Intent i = new Intent(android.content.Intent.ACTION_CALL, Uri.parse("tel:" + callstring));
startActivity(i);
your need to encode the # before using it above code will do the trick.
To use Intent.ACTION_CALL you need to add Permission
<uses-permission android:name="android.permission.CALL_PHONE"/> and since its a Dangerous permission you need to handle it Runtime for Android 6 and above.
You can rather use Intent.ACTION_DIAL which doesnt require any permission and will open the Phone app with the given number typed already, the user has to initiate the call.
Here is how to achieve this.
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*123*abcd#"));
startActivity(intent);

Type a phone number intent

How can I make my app type a given phone number without calling? I use:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phone));
startActivity(callIntent);
But that statement makes a call too.
Replace Intent.ACTION_CALL with Intent.ACTION_DIAL
You're using ACTION_CALL. You need to use ACTION_DIAL instead.
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:" + phone));
startActivity(callIntent);

Android - Send email with image attachment returning 0KB size

I created an app with action click to send email with image attachment file, I was think the code is working right, after I found the image size of attachment is 0kb, and when I clicked it, it said "Unable find the item", here is the code I use for
public void SendEmailWithAttachment(final String imageUrl){
String path = "file:///android_asset".concat(File.separator).concat(getString(R.string.sa_books_directory)).concat(File.separator); // Get the path file from my asset folder
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "This is subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email body");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path + "IndividualVillas/pages/" + imageUrl + ".jpg"));
startActivity(emailIntent);
}
I don't know where is the problem, I had tried to change the setType but it doesn't help me also. Any kind help will much appreciate :)
Sorry for my bad English
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
//emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,body);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(new StringBuilder()
.append("I think you'll like this ")
.append(wineName).append(".")
.append("<br /><br />Scanned it with the ")
.append(bottleRating+tastingNote)
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+winePic));
final PackageManager pm = ShareWineActivity.this.getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm")|| info.activityInfo.name.toLowerCase().contains("gmail"))
best = info;
if (best != null)
emailIntent.setClassName(best.activityInfo.packageName,best.activityInfo.name);
startActivityForResult(emailIntent, 2015);
Is the path correct? If you have double checked that then:
The problem here are privileges. If you want to make some private file accessible for other application then probably you want to use this simple, nice and clean solution: https://developer.android.com/reference/android/support/v4/content/FileProvider.html

Make a Call in on number followed by # key

I am working on the calling app where I make call on button click but if the number just followed by # then it does not take the # key at the last of phone number.
For Example if I want to make a call on *123# from app then it only shows *123 in the calling screen in phone. Please suggest me where I am going wrong.
Here is my code for call on *123# on button click.
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
callIntent.setData(Uri.parse("tel:" + "*123#"));
startActivity(callIntent);
try this...
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ Uri.encode("*123#")));
startActivity(callIntent);
You need to escape the # as a URI entity: %23

Categories

Resources