English 中文(简体)
行动:
原标题:ACTION_SEND used to send sms

我想开放本地申请,以寄送短片,但应该有电话号码。 我发现“行动”——但当我要求我履行职务时,它会犯以下错误:

04-26 11:59:15.991: ERROR/AndroidRuntime(20198): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO (has extras) }

我在此提出的法典:

    private void smsSend(String number) {
    Intent intent = new Intent(Intent.ACTION_SENDTO, null);
    intent.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
    startActivity(intent);
}

我知道,这很简单,但我不知道为什么不工作,我找不到任何hel的信息。

感谢任何建议。

最佳回答

为什么应该做罚款。

我的守则:

Uri uri = Uri.parse("smsto:0800000123");   
Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
it.putExtra("sms_body", "The SMS text");   
startActivity(it); 
问题回答

Thanks for the info ! Here is my solution using the previous info:

if (url.indexOf("tel:") > -1) {
    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
    return true;
}
else if (url.indexOf("sms:") > -1){
    startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse(url)));
    return true;
}

Best regards.

我认为,你应当使用以下法典:

Intent sendIntent = new Intent(Intent.ACTION_VIEW);

//use to fill the sms body
StringBuilder uri = new StringBuilder("sms:" + mobilenumber);
sendIntent.putExtra("sms_body", "");
sendIntent.setType("vnd.android-dir/mms-sms");
sendIntent.setData("");
startActivity(sendIntent);

我认为这可能有助于你。

On my side, the intent without uri parameter work for all devices, except for Pixel Phone where I need to use it, so I check the 2 ways:

    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    final Context context = activity.getApplicationContext();
    final String phoneNumber = "1234567890";
    final String msg = "Hello!";
    smsIntent.putExtra("address", phoneNumber);
    smsIntent.putExtra("sms_body", msg);
    smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |
            Intent.FLAG_ACTIVITY_CLEAR_TOP);

    final PackageManager manager = context.getPackageManager();
    List<ResolveInfo> infos = manager.queryIntentActivities(smsIntent, 0);
    if (infos.size() <1) {
        //No Application can handle your intent
        //try in a another way ...
        Uri uri = Uri.parse("smsto:"+phoneNumber);
        smsIntent = new Intent(Intent.ACTION_SENDTO, uri);
        smsIntent.putExtra("sms_body", msg);
        infos = manager.queryIntentActivities(smsIntent, 0);
    }

    if (infos.size() <1) {
        //No Application can handle your intent
        Log.e("SendMessage","No Application can handle your SMS intent");
    }

In kotlin following code works with number and custom message

val defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity)  
            val sendIntent = Intent(Intent.ACTION_SEND)
            sendIntent.type = "text/plain"
            sendIntent.putExtra("address", "sms:"+contactNumber)
            sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_msg_body))
            Timber.e("defaultSmsPackageName: "+defaultSmsPackageName)
            if (defaultSmsPackageName != null){ //Can be null in case that there is no default, then the user would be able to choose any app that support this intent.
                sendIntent.setPackage(defaultSmsPackageName)
                activity!!.startActivity(sendIntent)
            }




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签