fluttercommunity / flutter_sms

A Flutter plugin to Send SMS and MMS on iOS and Android. If iMessage is enabled it will send as iMessage on iOS. This plugin must be tested on a real device on iOS. Maintainer: @rodydavis
https://fluttercommunity.github.io/flutter_sms/
MIT License
246 stars 196 forks source link

PlatformException(device_not_capable, The current device is not ....... #41

Open makis73 opened 3 years ago

makis73 commented 3 years ago

Hello and congrats for your work ! 2.3.1 works on Android 6 - 11 but not on Android 5 ! PlatformException(device_not_capable, The current device is not ....... ! Your example also. Why can this happens ? Something about permissions ?

tilakdewangan commented 3 years ago

It does not work on Andriod 11 for me.

vizhan-lanars commented 3 years ago

@tilakdewangan @makis73

You need to update your Manifest file with

<uses-permission android:name="android.permission.SEND_SMS" />
<queries>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="smsto"/>
    </intent>
</queries>

And request SMS permission at runtime.

rohan20 commented 2 years ago

@vizhan-lanars Thanks for your answer. I tested and found out that we only need the <queries> tag, not the runtime SEND_SMS permission itself.

<!-- SEND_SMS runtime permission not needed -->
<queries>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="smsto"/>
    </intent>
</queries>
albrewot commented 2 years ago

@vizhan-lanars Thanks for your answer. I tested and found out that we only need the <queries> tag, not the runtime SEND_SMS permission itself.

<!-- SEND_SMS runtime permission not needed -->
<queries>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="smsto"/>
    </intent>
</queries>

Thanks for this, it worked.

Arjun2002tiwari commented 1 year ago

WHERE TO PASTE THIS IN WHICH SECTION?

savalet commented 1 year ago

WHERE TO PASTE THIS IN WHICH SECTION?

In android/app/src/main and it's AndroidManifest.xml

baimamboukar commented 1 year ago

WHERE TO PASTE THIS IN WHICH SECTION?

In android/app/src/main and it's AndroidManifest.xml

Directly after or insite application tag ?

damolator commented 1 year ago

The queries tag in the Android manifest.xml file should be placed outside the application tag.

Here's an example of the correct placement of the queries tag in the Android manifest.xml file:

<manifest ... > <application ... >

<queries>
     <intent>
         <action android:name="android.intent.action.SENDTO" />
         <data android:scheme="smsto"/>
     </intent>
</queries>

Placing the queries tag inside the application tag will result in a compilation error.

Terrence-Beckham commented 1 year ago

This Worked for me on Pixel 6 Android 13. Thx

jineshpatel2002 commented 1 year ago

Thanks @vizhan-lanars , my app was working perfectly fine before adding your suggested extra code but a week ago it stopped sending sms with the platform exception and I tried your solution and it worked :)

Also would appreciate any possible explanations to my query that : app was working perfectly fine before , with only single line config of :- <uses-permission android:name="android.permission.SEND_SMS" /> but stopped working a week ago and now today after adding these lines :-

<queries>
     <intent>
         <action android:name="android.intent.action.SENDTO" />
         <data android:scheme="smsto"/>
     </intent>
</queries>

to above-old configuration , the app started working fine again..!!!! what could be the reason for the same?

thefirebanks commented 1 year ago

In addition to the lines provided by @vizhan-lanars (thank you!!!!!!) I had to manually give the app permissions on my phone (by going to Settings -> Permission Manager -> SMS -> allow <APP NAME>) to actually send the message without opening the app (using the sendDirect parameter of _sendSMS). Otherwise, it works! (by opening the messaging app of my phone).

EDIT: Upon further read of the code here: https://github.com/fluttercommunity/flutter_sms/issues/67#issue-1275608493 I was able to add a runtime permission request using permission_handler and it solved my issue. Hope this helps!