Send MMS programmatically

I want to send MMS programmatically, I used the following code for it

Intent sendIntent1 = new Intent(Intent.ACTION_SEND); try { sendIntent1.setType("text/x-vcard"); sendIntent1.putExtra("address","0475223091"); sendIntent1.putExtra("sms_body","hello.."); sendIntent1.putExtra(Intent.EXTRA_STREAM, Uri.parse(vcfFile.toURL().toString())); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } startActivity(sendIntent1); 

The problem is that it directs the composing page of the message and requires the manual sending of SMS, and I do not want this without any notification that it should send. How can i do this?

SomeBody, please share my answer

+6
source share
3 answers

I finally found a solution that works 100%. See the github project https://github.com/klinker41/android-smsmms . (Anyone who finds this helpful, please donate to the author http://forum.xda-developers.com/showthread.php?t=2222703 ).

Please note that the required settings are only

 Settings sendSettings = new Settings(); sendSettings.setMmsc(mmsc); sendSettings.setProxy(proxy); sendSettings.setPort(port); 

you can get something like (found in APN software application on Android - answer from vincent091):

 Cursor cursor = null; if (Utils.hasICS()){ cursor =SqliteWrapper.query(activity, activity.getContentResolver(), Uri.withAppendedPath(Carriers.CONTENT_URI, "current"), APN_PROJECTION, null, null, null); } else { cursor = activity.getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), null, null, null, null); } cursor.moveToLast(); String type = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.TYPE)); String mmsc = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSC)); String proxy = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPROXY)); String port = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPORT)); 
+9
source

MMS is an HTTP request to Android. You must have mobile data to send MMS. The API set by Android to send MMS is missing because they have an API for SMS. If you want your application to send MMS, you will have to write everything. Please refer to the AOSP code. https://github.com/android/platform_packages_apps_mms OR you can just create an Intent and then run your own messaging app.

+2
source

Thus, you can directly use mms, providing mobile communication No and Subject. And attach the image.

 Uri uri = Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/test.png"); Intent i = new Intent(Intent.ACTION_SEND); i.putExtra("address","1234567890"); i.putExtra("sms_body","This is the text mms"); i.putExtra(Intent.EXTRA_STREAM,"file:/"+uri); i.setType("image/png"); startActivity(i); 
-1
source

Source: https://habr.com/ru/post/944857/


All Articles