前提・実現したいこと
python初心者です。
kivyで天気予報のWEBAPIを使ったアプリを作成しています。
デスクトップアプリとしては動作確認済みなのですが、
buildozerを使ってアンドロイド用にAPKファイル化して実機で動かすと、
WEBAPIを使用している部分が表示されなくなってしまいました。
アンドロイド上で動作するようにできないでしょうか
詳しい方のアドバイスをお待ちしています。
該当のソースコード
from kivy.network.urlrequest import UrlRequest import certifi as cfi class WeatherWidget(Screen): city = StringProperty('--') saiko = StringProperty("--") saite = StringProperty("--") forecast = [] def download_current_weather(self, city, *args, **kwargs): url = 'https://api.openweathermap.org/data/2.5/weather?q=' + city + '&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09' UrlRequest(url = url, on_success = self.show_current_weather, on_error = self.download_error, on_progress = self.progress, chunk_size = 40960,ca_file=cfi.where(), verify=True) def download_forecast(self, city, *args, **kwargs): url = 'https://api.openweathermap.org/data/2.5/forecast?q=' + city + '&cnt=8&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09' UrlRequest(url = url, on_success = self.show_forecast, on_error = self.download_error, on_progress = self.progress, chunk_size = 40960,ca_file=cfi.where(), verify=True) def download_error(self, request, error): self.notification = 'data could not be downloaded' def progress(self, request, current_size, total_size): self.notification = ('Downloading data: {} bytes of {} bytes'.format(current_size, total_size)) def show_current_weather(self, request, result): self.city = result.get('name','nn') self.notification = '' def show_forecast(self, request, result): self.forecast = result self.ids['grid'].clear_widgets() for count in self.forecast['list']: tenki = count['weather'][0]['main'] self.ids['grid'].add_widget(Label(text=strftime('%H:%M',gmtime(count['dt'])), font_size='30sp')) if tenki == "Clouds": self.ids['grid'].add_widget(Label(text="曇り", font_size='30sp')) if tenki == "Rain": self.ids['grid'].add_widget(Label(text="雨", font_size='30sp')) if tenki == "clear sky": self.ids['grid'].add_widget(Label(text="晴れ", font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['temp'] - 273.15) + '°C', font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['pop']*100) + '%', font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['humidity']) + '%', font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['wind']['speed']) + '(m/s)', font_size='30sp')) self.notification = '' class WeatherWidget2(Screen): city = StringProperty('--') forecast2 = [] def download_current_weather2(self, city, *args, **kwargs): url = 'https://api.openweathermap.org/data/2.5/weather?q=' + city + '&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09' UrlRequest(url = url, on_success = self.show_current_weather, on_error = self.download_error2, on_progress = self.progress2, chunk_size = 40960,ca_file=cfi.where(), verify=True) def download_forecast2(self, lat, lon, *args, **kwargs): url = 'https://api.openweathermap.org/data/2.5/onecall?lat=' + lat + '&lon=' + lon + '&exclude=current,minutely,hourly,alerts&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09' UrlRequest(url = url, on_success = self.show_forecast2, on_error = self.download_error2, on_progress = self.progress2, chunk_size = 40960,ca_file=cfi.where(), verify=True) def download_error2(self, request, error): self.notification = 'data could not be downloaded' def progress2(self, request, current_size, total_size): self.notification = ('Downloading data: {} bytes of {} bytes'.format(current_size, total_size)) def show_current_weather(self, request, result): self.city = result.get('name','nn') self.notification = '' def show_forecast2(self, request, result): self.forecast2 = result self.ids['grid2'].clear_widgets() for count in self.forecast2['daily']: dt=strftime('%a',gmtime(count['dt'])) tenki = count['weather'][0]['main'] if dt == "Mon": self.ids['grid2'].add_widget(Label(text ="月曜日", font_size='30sp')) if dt == "Tue": self.ids['grid2'].add_widget(Label(text ="火曜日", font_size='30sp')) if dt == "Wed": self.ids['grid2'].add_widget(Label(text ="水曜日", font_size='30sp')) if dt == "Thu": self.ids['grid2'].add_widget(Label(text ="木曜日", font_size='30sp')) if dt == "Fri": self.ids['grid2'].add_widget(Label(text ="金曜日", font_size='30sp')) if dt == "Sat": self.ids['grid2'].add_widget(Label(text ="土曜日", font_size='30sp')) if dt == "Sun": self.ids['grid2'].add_widget(Label(text ="日曜日", font_size='30sp')) if tenki == "Clouds": self.ids['grid2'].add_widget(Label(text="曇り", font_size='30sp')) if tenki == "Rain": self.ids['grid2'].add_widget(Label(text="雨", font_size='30sp')) if tenki == "Clear": self.ids['grid2'].add_widget(Label(text="晴れ", font_size='30sp')) self.ids['grid2'].add_widget(Label(text='{:.0f}'.format(count['temp']['max'] - 273.15) + '°C', font_size='30sp')) self.ids['grid2'].add_widget(Label(text='{:.0f}'.format(count['temp']['min'] - 273.15) + '°C', font_size='30sp')) self.ids['grid2'].add_widget(Label(text='{:.0f}'.format(count['pop']*100) + '%', font_size='30sp')) self.notification = '' def show_forecast(self, request, result): self.forecast = result self.ids['grid'].clear_widgets() for count in self.forecast['list']: tenki = count['weather'][0]['main'] self.ids['grid'].add_widget(Label(text=strftime('%H:%M',gmtime(count['dt'])), font_size='30sp')) if tenki == "Clouds": self.ids['grid'].add_widget(Label(text="曇り", font_size='30sp')) if tenki == "Rain": self.ids['grid'].add_widget(Label(text="雨", font_size='30sp')) if tenki == "clear sky": self.ids['grid'].add_widget(Label(text="晴れ", font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['temp'] - 273.15) + '°C', font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['pop']*100) + '%', font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['humidity']) + '%', font_size='30sp')) self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['wind']['speed']) + '(m/s)', font_size='30sp')) self.notification = ''
試したこと
buildozer.specでインターネットアクセスの許可
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。