Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Send a background SMS via dual sim Android phones

F1FreakF1Freak USMember ✭✭

Guys, I am sending a background SMS on dual sim Android phones.

Its fully working on 22 and higher SDKs by this code -

SmsManager.GetSmsManagerForSubscriptionId(sub.SubscriptionId).SendTextMessage("somephonenumber", null, sub.DisplayName, null, null);

For lower end SDKs, I wrote the below code using reflections -

Java.Lang.Reflect.Method serviceMethod = Java.Lang.Class.ForName("android.os.ServiceManager").GetDeclaredMethod("getService", new Java.Lang.Class[] { Java.Lang.Integer.Type });//new Java.Lang.Class[] { }); serviceMethod.Accessible = true; Java.Lang.Object param = serviceMethod.Invoke(null, name); serviceMethod = Java.Lang.Class.ForName("com.android.internal.telephony.ISms$Stub").GetDeclaredMethod("asInterface", new Java.Lang.Class[] { }); serviceMethod.Accessible = true; Java.Lang.Object stubObj = serviceMethod.Invoke(null, param); Java.Lang.Class[] _objclass = new Java.Lang.Class[10]; if (Convert.ToInt16(Build.VERSION.SdkInt) < 18) { serviceMethod = stubObj.Class.GetMethod("sendText", _objclass); serviceMethod.Invoke(stubObj, toNum, centerNum, smsText, sentIntent, deliveryIntent); } else { serviceMethod = stubObj.Class.GetMethod("sendText", _objclass); serviceMethod.Invoke(stubObj, "", toNum, centerNum, smsText, sentIntent, deliveryIntent); }

I am stuck with this exception -

{Java.Lang.NoSuchMethodException: getService [int] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00085] in /Users/builder/data/lanes/4009/3a62f1ea/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11283 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00017] in /Users/builder/data/lanes/4009/3a62f1ea/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:339 at Java.Lang.Class.GetDeclaredMethod (System.String name, Java.Lang.Class[] parameterTypes) [0x00038] in /Users/builder/data/lanes/4009/3a62f1ea/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Java.Lang.Class.cs:602

Sign In or Register to comment.