No Activity found to handle Intent { act=android.intent.action.DIAL } - android

I want to open my phone dialer .But it shows error. I have declared permissions for CALL_PHONE on Android Manifest and also declared class in Android Manifest.
case R.id.action_call:
Log.d("Action_call","INside Action call");
Intent dialer = new Intent(Intent.ACTION_DIAL);
startActivity(dialer);
return true;

You don't need any permissions for ACTION_DIAL Intent. So remove CALL_PHONE permission from AndroidManifest.xml.
You have not pass any number to fire dial Intent.
Use tel: followed by the phone number as the value passed to Uri.parse():
Try this code.
String number = "1234567890";
Uri number = Uri.parse("tel:" + number);
Intent dial = new Intent(Intent.ACTION_DIAL);
dial.setData(number);
startActivity(dial);
EDIT:
You can first check whether telephony is supported on device
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
I hope it helps!

Use Uri to parse number..
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:"+phone)); //String phone
startActivity(call);

Use try/catch.
Use Uri to parse number.
Don't need any permissions for ACTION_DIAL intent.
try{
Intent call_intent = new Intent(Intent.ACTION_DIAL);
call_intent.setData(Uri.parse("tel:"+phone_number));
startActivity(call_intent);
}catch(Exception e){
}

Related

Intent.ACTION_DIAL with number ending with #

So I'm trying to send a number via Intent.ACTION_DIAL ending with # i.e for example *123#. But when the Android Dialer app is started, there is only *123 (# is missing).
I'm using following code to trigger the Dial Application of Android.
Uri number = Uri.parse("tel:*124#");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);
Anticipated Thanks!!
.
You need to properly encode the hash tag (#). In your URL requests it should be %23, so replacing it with %23 will do the trick.
Uri number = Uri.parse("tel:*124%23");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);
You can also let URI do the encoding:
String encodedPhoneNumber = String.format("tel:%s", Uri.encode("*1234#"));
Uri number = Uri.parse(encodedPhoneNumber);
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);
The answer could be related with this link
initiate a phone call on android with special character #
This line could be the key
Uri.parse("tel:"+Uri.encode("*124#"));

Using intent.Action_call for user inputted number

Help me modify with necessary changes needed to use the value/string(number) passed by user for phone-calling that string itself
Intent phnIntent = new Intent(Intent.ACTION_CALL);
phnIntent.setData(Uri.parse("tel:+91987654321"));
you can use like this :
String strTelNo = "+91987654321";
Intent intent = new Intent("android.intent.action.CALL");
Uri data = Uri.parse("tel:"+ strTelNo );
intent.setData(data);
startActivity(intent);
Try this link.
Make sure you add the necessary permission in the Android Manifest.
<uses-permission android:name="android.permission.CALL_PHONE" />
Just add the line startActivity(phnIntent);
EDIT:
Activity A
Intent someIntent = new Intent(A.this, B.class);
someIntent.putExtra("phoneNumber", number);
startAcitivty(someIntent);
Acitivity B
Bundle extras = getIntent().getExtras();
String number = extras.getInt("phoneNumber");
Use the number string to make the call.

Android send SMS from tablet using SMS intent?

I would like to know if it is possible to send a SMS from an Android tablet using the SMS intent? If this is not possible, what are my options?
I would like to know if it is possible to send a SMS from an Android tablet using the SMS intent?
There isn't really an "SMS" Intent. There are ACTION_SEND and ACTION_SENDTO Intent actions that could result in an SMS being sent.
With respect to "tablets", most devices with above-average screen sizes do not have telephony capability, and therefore cannot do anything with SMSes, let alone send them in response to startActivity() on some Intent.
what are my options?
If you absolutely have to be able to send SMS messages, add <uses-feature android:name="android.hardware.telephony"/> to your manifest, so your app will only be installed on devices that have telephony capability.
If you would like to send SMS messages if that is possible, but work around it if it is not possible, you will want to do three things:
Add <uses-feature android:name="android.hardware.telephony" android:required="false"/> to your manifest
Use PackageManager and hasSystemFeature() to see if you actually have telephony capability at runtime
For devices that have telephony capability, before you call startActivity() on your "SMS Intent", use PackageManager and queryIntentActivities() to see if there is anything on the device that will respond to that Intent, or wrap your startActivity() call in an exception handler to catch the
ActivityNotFoundException
String smsNumber = "your number here";
String smsText = "Your text";
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"
+ phoneNumber)));
Try this.
How to check if a tablet has sms service available:
Here the third solution which CommonsWare described in his answer as a method:
public static boolean hasSmsService(Context context)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:123456789"));
PackageManager pm = context.getPackageManager();
List<ResolveInfo> res = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if(res.size() > 0)
{
return true;
}
return false;
}
}
This is wok for you. try it.........
Method :
CAll on button click event.....
sendSMS("Any text",number,sms_string);
Now, declare this one out of oncreate();
public static void sendSMS(String status, String phoneNumber, String message) {
Log.e("", "Page : " + status + ", No : " + phoneNumber
+ ",Message Length: " + message.length() + ", Message : "
+ message);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}

Open a facebook page from android app?

How can I start an intent to open a Facebook application on a phone and navigate to the prefered page in Facebook?
I tried:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
intent.putExtra("extra_user_id", "123456789l");
this.startActivity(intent);
Well, whatever I write to "1234567891", it is always navigating to my page. Always to me and not else.
How could I do this?
Here is the best and simple way to do it.
Just follow the code
public final void Facebook() {
final String urlFb = "fb://page/"+yourpageid;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(urlFb));
// If Facebook application is installed, use that else launch a browser
final PackageManager packageManager = getPackageManager();
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() == 0) {
final String urlBrowser = "https://www.facebook.com/pages/"+pageid;
intent.setData(Uri.parse(urlBrowser));
}
startActivity(intent);
}
I had the exactly same problem, sent the user id but for some reason, my profile always opened instead of the friend's profile.
The problem is that if you pass the String of the Long object that represents the Facebook UID, or even a long primitive type, the intent won't be able to read it later. You need to pass a real Long.
So the complete code is:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
Long uid = new Long("123456789");
intent.putExtra("extra_user_id", uid);
startActivity(intent);
Ok enjoy and hope this helps :-)
Maxim
try this code :
String facebookUrl = "https://www.facebook.com/<id_here>";
try {
int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) {
Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else {
Uri uri = Uri.parse("fb://page/<id_here>");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
} catch (PackageManager.NameNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}
This solution won't work any more. The new version of the facebook app doesn't support anymore those kind of intents. See here the bug report
The new solution is to use the iPhone scheme mechanism (Yes, facebook decided to support the iPhone mechanism in Android instead of the implicit intent mechanism of Android).
So in order to open the facebook app with a user profile all you need to do is:
String facebookScheme = "fb://profile/" + facebookId;
Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
startActivity(facebookIntent);
If you are looking for other actions you can use the following page for all available actions (/you have to test it though, since I didn't find an official publication of facebook about this)

Android Intent Chooser to only show E-mail option

My app integrates e-mail where the user can submit a bug report, feedback, etc. from the app directly. I'm using the application/octet-stream as the SetType for the Intent. When you go to submit the e-mail you get the content chooser and it shows various items from Evernote, Facebook, E-mail, etc.
How can I get this chooser to only show E-mail so as not to confuse the user with all these other items that fit the content chooser type?
Thank you.
To solve this issue simply follow the official documentation. The most important consideration are:
The flag is ACTION_SENDTO, and not ACTION_SEND.
The setData of method of the intent,
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
If you send an empty Extra, the if() at the end won't work and the app won't launch the email client.
This works for me. According to Android documentation. If you want to ensure that your intent is handled only by an email app (and not other text messaging or social apps), then use the ACTION_SENDTO action and include the "mailto:" data scheme. For example:
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);
}
}
https://developer.android.com/guide/components/intents-common.html#Email
I am presuming that you are using the ACTION_SEND Intent action, since you did not bother to actually state what you're using, but you agreed with #Aleadam's comment.
I'm using the application/octet-stream as the SetType for the Intent.
Nothing in that sentence limits things to email.
ACTION_SEND is a generic Intent action that can be supported by any application that wants to. All you do is indicate what data you are sharing and the MIME type of that data -- from there, it is up to the user to choose from available activities.
As #Jasoon indicates, you can try message/rfc822 as the MIME type. However, that is not indicating "only offer email clients" -- it indicates "offer anything that supports message/rfc822 data". That could readily include some application that are not email clients.
If you specifically want to send something by email, integrate JavaMail into your app, or write an email forwarding script on your Web server and invoke it, or something. If you use ACTION_SEND, you are implicitly stating that it is what the user wants that matters, and you want the user to be able to send such-and-so data by whatever means the user chooses.
Just struggled with this problem while implementing a Magic Link feature, a chooser intent for all installed email apps:
Chooser Intent Screenshot
private void openEmailApp() {
List<Intent> emailAppLauncherIntents = new ArrayList<>();
//Intent that only email apps can handle:
Intent emailAppIntent = new Intent(Intent.ACTION_SENDTO);
emailAppIntent.setData(Uri.parse("mailto:"));
emailAppIntent.putExtra(Intent.EXTRA_EMAIL, "");
emailAppIntent.putExtra(Intent.EXTRA_SUBJECT, "");
PackageManager packageManager = getPackageManager();
//All installed apps that can handle email intent:
List<ResolveInfo> emailApps = packageManager.queryIntentActivities(emailAppIntent, PackageManager.MATCH_ALL);
for (ResolveInfo resolveInfo : emailApps) {
String packageName = resolveInfo.activityInfo.packageName;
Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
emailAppLauncherIntents.add(launchIntent);
}
//Create chooser
Intent chooserIntent = Intent.createChooser(new Intent(), "Select email app:");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, emailAppLauncherIntents.toArray(new Parcelable[emailAppLauncherIntents.size()]));
startActivity(chooserIntent);
}
There is a way more generic to do that, working with any MIME type.
See this post: How to customize share intent in Android?
It is possible to limit the choices of an intent chooser to just a few options. The code in the answer to this question is a good example. In essence, you would have to create a List of LabeledIntents to provide to the intent chooser, that will then include it in its list. Note that this solution works not on exclusion (certain apps are excluded while the rest remain) but instead you have to pick which apps to display. Hope it helps!
It works on all devices. It will show only Email Apps
public static void shareViaMail(Activity activity, String title, String body, String filePath) {
Uri URI = Uri.parse("file://" + filePath);
final Intent emailIntent = new Intent(Intent.ACTION_VIEW);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"contact#brightsociety.com"});
if (URI != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
}
try {
activity.startActivity(emailIntent);
} catch (Exception e) {
((BaseActivity) activity).showToast("Gmail App is not installed");
e.printStackTrace();
}
}
Kotlin Answer
If you need to show only email apps and then you want to open only inbox (not open new email writing), you need to do A and B:
A) Add below code in your AndroidManifest.xml file for Android 11 because of package visibility update of Android 11 :
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
<intent>
<action android:name="android.intent.action.CHOOSER" />
</intent>
</queries>
B) Use below function to show email chooser:
// Show email app list.
fun showEmailAppList() {
// Email app list.
val emailAppLauncherIntents: MutableList<Intent?> = ArrayList()
// Create intent which can handle only by email apps.
val emailAppIntent = Intent(Intent.ACTION_SENDTO)
emailAppIntent.data = Uri.parse("mailto:")
// Find from all installed apps that can handle email intent and check version.
val emailApps = packageManager.queryIntentActivities(
emailAppIntent,
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) 0 else PackageManager.MATCH_ALL
)
// Collect email apps and put in intent list.
for (resolveInfo in emailApps) {
val packageName = resolveInfo.activityInfo.packageName
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
emailAppLauncherIntents.add(launchIntent)
}
// Create chooser with created intent list to show email apps of device.
val chooserIntent = Intent.createChooser(Intent(), "OPEN EMAIL APP")
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, emailAppLauncherIntents.toTypedArray())
startActivity(chooserIntent)
}
Result:
It works on all devices.It will show only Email Apps
public static void shareViaMail(Activity activity, String title, String body, String filePath) {
Uri URI = Uri.parse("file://" + filePath);
final Intent emailIntent = new Intent(Intent.ACTION_VIEW);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"xyz#gmail.com"});
/*if you want to attach something*/
if (URI != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
}
try {
activity.startActivity(emailIntent);
} catch (Exception e) {
((BaseActivity) activity).showToast("Gmail App is not installed");
e.printStackTrace();
}
}
Solution is very simple:
Intent testIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "blah blah subject" + "&body=" + "blah blah body" + "&to=" + "sendme#me.com");
testIntent.setData(data);
startActivity(testIntent);
See: http://www.gaanza.com/blog/email-client-intent-android/
After a lot of searching and testing, I finally found a perfect solution. Thanks to the Open source developer, cketti for sharing his/her concise and neat solution.
String mailto = "mailto:bob#example.org" +
"?cc=" + "alice#example.com" +
"&subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(bodyText);
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(mailto));
try {
startActivity(emailIntent);
} catch (ActivityNotFoundException e) {
//TODO: Handle case where no email app is available
}
And this is the link to his/her gist.

Categories

Resources