Jan-18-2024, 01:27 PM
I created a simple app for viewing my weekly meal plan. It reads the SQLite database. The app worked on my old smartphone; however, it does not work on my new Pixel 7 smartphone. The issue is that my app does not have access to the smartphone's storage, where the database is localized. It was possible to grant that access with my old smartphone; however, it is not possible with the new one. So, I have to modify my app to make it request such permission. Unfortunately, I don't know how to do that. I tried with ChatGPT, but it didn't work.
Here is my simple code, which worked on my old smartphone:
https://pastebin.com/Rfd79a32
And here is the functions.py file:
https://pastebin.com/TkG82VhY
How to solve this problem?
Here is my simple code, which worked on my old smartphone:
from kivy.properties import StringProperty from kivy.lang import Builder from kivy.uix.tabbedpanel import TabbedPanel from kivymd.app import MDApp import functions meals = functions.getMealList() meal_list_for_kv_file = functions.getMealsFor_kv_File(meals) current_meal_name = '' kv_string = ''' <MyLayout> do_default_tab: False size_hint: 1, 1 # ft_top, left_mid, left_bottom, top_left, # top_mid, top_right, right_top, right_mid, # right_bottom, bottom_left, bottom_mid, # bottom_right. tab_pos: 'top_mid' TabbedPanelItem: text: "Meal List" ScrollView: MDList: {0} TabbedPanelItem: text: "Meal" on_release: root.pressedMealTab() BoxLayout: orientation: 'vertical' Label: font_size: self.width/30 text_size: self.size halign: 'left' valign: 'top' id: Label1Tab2_id text: root.meal_ingredients Label: font_size: self.width/40 text_size: self.size halign: 'left' valign: 'top' id: Label2Tab2_id text: root.meal_recipe TabbedPanelItem: text: "Week" on_release: root.pressedWeekTab() BoxLayout: orientation: 'vertical' Label: text_size: self.size halign: 'left' valign: 'middle' id: Label1Tab3_id text: root.monday_meals Label: text_size: self.size halign: 'left' valign: 'middle' id: Label2Tab3_id text: root.thuesday_meals Label: text_size: self.size halign: 'left' valign: 'middle' id: Label3Tab3_id text: root.wednesday_meals Label: text_size: self.size halign: 'left' valign: 'middle' id: Label4Tab3_id text: root.thursday_meals Label: text_size: self.size halign: 'left' valign: 'middle' id: Label5Tab3_id text: root.friday_meals Label: text_size: self.size halign: 'left' valign: 'middle' id: Label6Tab3_id text: root.saturday_meals Label: text_size: self.size halign: 'left' valign: 'middle' id: Label7Tab3_id text: root.sunday_meals '''.format(meal_list_for_kv_file) # print(kv_string) # Designate Our .kv design file Builder.load_string(kv_string) class MyLayout(TabbedPanel): meal_ingredients = StringProperty() meal_recipe = StringProperty() monday_meals = StringProperty() thuesday_meals = StringProperty() wednesday_meals = StringProperty() thursday_meals = StringProperty() friday_meals = StringProperty() saturday_meals = StringProperty() sunday_meals = StringProperty() def pressedMealTab(self): global current_meal_name try: self.ids.Label1Tab2_id.text = functions.getMealIngredientString(current_meal_name) self.ids.Label2Tab2_id.text = functions.getMealRecipe(current_meal_name) except: print("YOU HAVEN'T CHOOSE A MEAL") def pressedWeekTab(self): try: self.ids.Label1Tab3_id.text = functions.getMealsForASingleDay("MONDAY", "weekly_menu1_1") self.ids.Label2Tab3_id.text = functions.getMealsForASingleDay("THUESDAY", "weekly_menu1_2") self.ids.Label3Tab3_id.text = functions.getMealsForASingleDay("WEDNESDAY", "weekly_menu1_3") self.ids.Label4Tab3_id.text = functions.getMealsForASingleDay("THURSDAY", "weekly_menu1_4") self.ids.Label5Tab3_id.text = functions.getMealsForASingleDay("FRIDAY", "weekly_menu1_5") self.ids.Label6Tab3_id.text = functions.getMealsForASingleDay("SATURDAY", "weekly_menu1_6") self.ids.Label7Tab3_id.text = functions.getMealsForASingleDay("SUNDAY", "weekly_menu1_7") except: print("CAN'T GET WEEKLY MENU") class MealPlannerAndroid(MDApp): def build(self): return MyLayout() def pressedMealOnList(self, pressed, list_id): pressed.tertiary_text = f"You Pressed {list_id}" #print(pressed.tertiary_text) global current_meal_name current_meal_name = list_id if __name__ == '__main__': MealPlannerAndroid().run()And here is the modified by chatGPT code, which does not work:
https://pastebin.com/Rfd79a32
And here is the functions.py file:
https://pastebin.com/TkG82VhY
How to solve this problem?