Android Question Send and receive SMS

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to everybody
Some years ago I wrote an app that sends and receives SMS. It was working, till 2022, sending and receiving SMS.. It is not a GooglePlay App, but just for my own use. I am using PhoneLibrary and PhoneSms object.
Now i need to work with it again, but the App crashes when I use the following code:
B4X:
dim RispSms as PhoneSms
RispSms.Send2(PairedPhone,Cosa,True,True)
The error is:
java.lang.SecurityException: Sending SMS message: uid 10074 does not have android.permission.SEND_SMS.
The manifest is:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(SmsModule,
<intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
'End of default text.
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
I don't have clear ideas on this topic, and where and if to add the permissions required. BTW, maybe on older devices it will work? As a matter of fact I got the error on a newer Phone, while the App worked on older Phones (and it could still run on these latter).
Thanks for ay hint.
 
Solution
Hi Thanks for your attention. I have solved the SendSms error. My mistake was that, in the old App, there was not an explicit call to RuntimePermissions:
B4X:
rp.CheckAndRequest(rp.PERMISSION_SEND_SMS)
This for sending resolves. Now I have to see for receiving. Thanks for now.

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Btw I added to the previous mainfest, the following:

AddPermission(android.permission.SEND_SMS)

But no result.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
I have read the DonManfred and LucaMs links, before posting the question. There is written That, provided that it is not a GooglePlay App, I can send and receive Sms. An now I found another test App that sends SMS, on same device. Therefore perhaps I can understand why the first one crashes. BUT, to simplify my life, the first App, if used for receiving, now says "Cannot start a receiver in debug mode" --- of course if run in Release Mode. Resuming, while for Sending maybe I can resolve, receiving seems now more difficult.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi Thanks for your attention. I have solved the SendSms error. My mistake was that, in the old App, there was not an explicit call to RuntimePermissions:
B4X:
rp.CheckAndRequest(rp.PERMISSION_SEND_SMS)
This for sending resolves. Now I have to see for receiving. Thanks for now.
 
Upvote 0
Solution

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Ok. The problem was the same: add runtime permission also for RECEIVE_SMS. A lot of noise for (almost) nothing. Everything works. Sorry.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…