file: AndroidManifest.xml to configure #3108
mymane1433223
started this conversation in
Debugging help
Replies: 1 comment
-
No, because it's given you an impossible combination of BeeWare and Kivy code. If you want to write a BeeWare app then please follow the BeeWare documentation: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
GPT told me to be aware that on Android, permissions need to be added to AndroidManifest.xml, but I found that this file is rewritten every time it is packaged. Should I listen to GPT's instructions
Chatgpt's original reply:
Sorry, the previous code did not solve your problem. According to the error message you provided: ValueError: Application has not set a main window., This usually means that in the startup method of the application, self.mainw_window is not set or displayed correctly. Please ensure that you have created and displayed the main window correctly in the startup method. Here is a complete example showing how to set the main window in the Toga application and add a button to get the current position and display it on a label:
python
Copy code
import toga
from toga.style import Pack
from toga.style.pack import COLUMN
from plyer import gps
class LocationApp(toga.App):
def startup(self):
#Create main window
self.main_window = toga.MainWindow(title=self.formal_name)
#Create a vertically arranged container
main_box = toga.Box(style=Pack(direction=COLUMN, padding=10))
#Create labels that display location information
Self. location_Label=toga. Label ('Current location: unknown ', style=Pack(padding=(0, 5)))
#Create a button to retrieve location
get_location_button = toga.Button(
'Get current location',
on_press=self.get_location,
style=Pack(padding=5)
)
#Add labels and buttons to the container
main_box.add(self.location_label)
main_box.add(get_location_button)
#Set the content of the main window
self.main_window.content = main_box
#Display the main window
self.main_window.show()
def get_location(self, widget):
try:
#Start GPS service
gps.configure(on_location=self.on_location)
gps.start()
except NotImplementedError:
The GPS function is not available on this device
def on_location(self, **kwargs):
#Obtain latitude and longitude
Latitude=kwargs.get ('lat ',' unknown ')
Longitude=kwargs.get ('lon ',' unknown ')
#Update label text
Self. location_1abel.text=f 'Current location: latitude {latitude}, Longitude
#Stop GPS service
gps.stop()
def main():
return LocationApp()
if name == 'main':
main().main_loop()
Please note that when using the GPS module of Plyer, it is necessary to enable location services on the device and ensure that the application has access to the location. On Android, you need to add the following permissions in AndroidManifest.xml:
xml
Copy code
On iOS, you need to configure the location usage description in the app's settings. In addition, make sure to add a dependency on ply in pyproject.toml:
toml
Copy code
[tool.briefcase.app.your_app_name]
requires = [
"toga",
"plyer",
#Other dependencies
]
Please replace your_app_name with your app name. If you still encounter the error 'GPS' object has no attribute' get_rocation 'at runtime, it may be due to some functionalities of the splicer not being implemented on a specific platform. Please refer to the official documentation of Plyer to learn about the features available on various platforms. I hope this code and instructions can help you solve the problem. If the problem persists, please provide more detailed information so that we can further assist you.
source
The above text is machine translated, including this sentence. If there are any inappropriate parts, please understand
Beta Was this translation helpful? Give feedback.
All reactions