Android Question "auto" SMS with no SEND_SMS permission?

boten

Active Member
Licensed User
Longtime User
My old app send SMS using the (now unallowed) SEND_SMS permission.
The SMS was sent "automatically" without any action by the user.

B4X:
Sub Process_Globals
Dim smsmsg As PhoneSms
....
End Sub

Sub SendLargeSms(Destination As String, Message As String)
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
   Dim parts As Object
   parts = r.RunMethod2("divideMessage", Message, "java.lang.String")
   r.RunMethod4("sendMultipartTextMessage", _
    Array As Object(Destination, Null, parts, Null, Null), _
    Array As String("java.lang.String", "java.lang.String", _
    "java.util.ArrayList", "java.util.ArrayList", "java.util.ArrayList"))
End Sub

Now I'm trying to conform to the new rule of no SEND_SMS permission using Erel's code:
B4X:
Sub SendLargeSmsNEW(Destination As String, Message As String)
Dim In As Intent
Dim number  As String
number=Destination
In.Initialize(In.ACTION_VIEW, "sms:" & number)
In.PutExtra("sms_body", Message)
StartActivity(In)

When the app sends the SMS, the user get a message asking to choose which app to use for sending (messaging is one of options)
After the user chooses messaging (just once), the text appears in messaging and the user needs to actually send the SMS.


I the tried to change the intent to:
B4X:
In.Initialize(In.ACTION_SEND, "sms:" & number)
in order for the sms to be send automatically.

This crashed (log follows below)

How can the SMS be send WITHOUT ANY user intervention? (no SEND_SMS permission allowed)


B4X:
eifocode_sendlargesmsnew (java line: 884)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=sms:xxxxxxxxxx flg=0x10000000 (has extras) }
   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1659)
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
   at android.app.ContextImpl.startActivity(ContextImpl.java:1240)
   at android.app.ContextImpl.startActivity(ContextImpl.java:1222)
   at android.content.ContextWrapper.startActivity(ContextWrapper.java:291)
   at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:850)
   at boten.eifo.eifocode._sendlargesmsnew(eifocode.java:884)
   at boten.eifo.eifocode._sendlargesms(eifocode.java:767)
   at boten.eifo.eifocode._sendmissing(eifocode.java:1000)
   at boten.eifo.eifoserv._do_work(eifoserv.java:191)
   at boten.eifo.eifoserv._service_start(eifoserv.java:286)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
   at boten.eifo.eifoserv.handleStart(eifoserv.java:105)
   at boten.eifo.eifoserv.access$000(eifoserv.java:8)
   at boten.eifo.eifoserv$1.run(eifoserv.java:70)
   at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:105)
   at boten.eifo.eifoserv.onStartCommand(eifoserv.java:68)
   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2765)
   at android.app.ActivityThread.access$2000(ActivityThread.java:152)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1385)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:231)
   at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:170)
   at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:441)
   at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:420)
   at boten.eifo.main._kidupdt_click(main.java:2329)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
   at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
   at android.view.View.performClick(View.java:4354)
   at android.view.View$PerformClick.run(View.java:17961)
   at android.os.Handler.handleCallback(Handler.java:725)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:5328)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
   at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Pause, UserClosed = false **
How can the SMS be send WITHOUT ANY user intervention? (no SEND_SMS permission allowed)
 

DonManfred

Expert
Licensed User
Longtime User
How can the SMS be send WITHOUT ANY user intervention? (no SEND_SMS permission allowed)
i don´t think this is possible without your app is defined as Standard-SMS App on this device.
On Higher Android versions only the defauld SMS App has such rights. And even here: The permission SEND_SMS must be given.
But you may be able to send a SMS without user intervention.
 
Last edited:
Upvote 0
Top