API calls made in Ionic 4 app not working on Android device

此生再无相见时 提交于 2020-01-11 11:38:16

问题


I am able to run my ionic app on my laptop by using the ionic lab command.

The app makes calls to the IMDB api, & displays data retrieved from it.

Now, I am trying to run the app on an android device. by using the following command: ionic cordova run android --device.

The app appears on my phone, but when I search for IMDB data, no results are appearing.

Below is the service I am using to make calls to the API:

export class MovieService {

  url = 'http://www.omdbapi.com/';
  apiKey = 'myKey';

  constructor(private http: HttpClient) { }

  searchData(title: string, type: SearchType): Observable<any> {
    return this.http.get(`${this.url}?s=${encodeURI(title)}&type=${type}&apikey=${this.apiKey}`)
      .pipe(
        map(results => {
          console.log('RAW', results);
          return results['Search'];
        })
      );
  }

  getDetails(id): Observable<any> {
    return this.http.get(`${this.url}?i=${id}&plot=full&apikey=${this.apiKey}`);
  }
}

Can someone please tell me why the app is working on my laptop, but when I try to use it on my phone it isn't working as expected?


回答1:


Probably one reason is that you are using http not https.

Android restricted access to non-secure feeds in a recent security update.

Try:

url = 'https://www.omdbapi.com/';


来源:https://stackoverflow.com/questions/57433362/api-calls-made-in-ionic-4-app-not-working-on-android-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!