ACTION_SEND used to send sms

后端 未结 5 1139
故里飘歌
故里飘歌 2021-01-04 19:23

I want to open native application to send sms but there should be already phone number. I found ACTION_SEND but when I\'m calling my function it\'s return error that:

<
5条回答
  •  长发绾君心
    2021-01-04 19:56

    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 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");
        }
    

提交回复
热议问题