Reputation: 1
Voici la traduction en anglais de votre message, avec les corrections nécessaires :
Hello,
I'm trying to create an Android app with Kivy and Python to send SMS messages. The problem is that Android limits the automatic sending of SMS messages by an app to a certain number per 30 minutes. I wanted to make my app the default messaging app on the phone, so I tried the following code:
from kivy.app import App
from kivy.uix.button import Button
from jnius import autoclass
Intent = autoclass('android.content.Intent')
TelephonySms = autoclass('android.provider.Telephony')
class SmsApp(App):
def build(self):
button = Button(text='Set as Default SMS App')
button.bind(on_press=self.set_default_sms_app)
return button
def set_default_sms_app(self, instance):
intent = Intent(TelephonySms.Sms.Intents.ACTION_CHANGE_DEFAULT)
intent.putExtra(TelephonySms.Sms.Intents.EXTRA_PACKAGE_NAME, 'org.test.smsapp')
currentActivity = autoclass('org.kivy.android.PythonActivity').mActivity
currentActivity.startActivity(intent)
if __name__ == '__main__':
SmsApp().run()
Unfortunately, this results in an error:
02-04 00:27:27.056 22875 22947 I python : AttributeError: type object 'android.provider.Telephony' has no attribute 'Sms'
02-04 00:27:27.056 22875 22947 I python : Python for android ended.
I really can't find a solution. I've tried several things, but each time it seems not to set the app as the default messaging app. If anyone can help, that would be great! Thanks in advance.
from kivy.app import App from kivy.uix.button import Button from jnius import autoclass
Intent = autoclass('android.content.Intent') TelephonySms = autoclass('android.provider.Telephony')
class SmsApp(App): def build(self): button = Button(text='Set as Default SMS App') button.bind(on_press=self.set_default_sms_app) return button
def set_default_sms_app(self, instance):
intent = Intent(TelephonySms.Sms.Intents.ACTION_CHANGE_DEFAULT)
intent.putExtra(TelephonySms.Sms.Intents.EXTRA_PACKAGE_NAME, 'org.test.smsapp')
currentActivity = autoclass('org.kivy.android.PythonActivity').mActivity
currentActivity.startActivity(intent)
if name == 'main': SmsApp().run()
Upvotes: 0
Views: 14