0

I am new to ionic.

I am developing a basic informational app.

I am running it on the browser, emulator, real device it works perfectly but then I tried to run it on Android version 9 it didn't work.

It returns [object object] While login.

I take input from ion-input. In all lower versions, users can fill the detail but in Android P when I click to fill the detail it didn't work. I can't write anything. But after clicking the button I can fill the detail.

When all field is written and on login, it returns [object object].

enter image description here

In all lower versions of Android, it works perfectly. Users can log in.

auth-service.ts

postData(credentials, type) {

    return new Promise((resolve, reject) => {

      let data: Observable<any> = this.http.post(baseURL + type, credentials);

      data.subscribe(response => {
        // console.log("Auth POST Response : " , response);
        for (let data of response) {
          resolve(data);
        }
      }, err => {
        console.log("Error", err);
        reject(err);
      }, () => {
        console.log('completed');
      });

    });
  }     

login.ts

login() {
      let loading = this.loadingCtrl.create({
        spinner: 'circles',
        content: 'Please wait...'
      });
      loading.present();

      let postData = new FormData();
      postData.append('contact_no', this.userData.contact_no);
      postData.append('password', this.userData.password);
      postData.append('fcm_id', this.userData.fcm_id);
      postData.append('imei_no', this.deviceId);

      this.authService.postData(postData, "login.php").then((result) => {
        this.responseData = result;
        console.log("res : ", this.responseData);
        this.success = this.responseData.success;
          console.log("this.success : ", this.success);
          if (this.success == 1) {
            let userDeatil = this.responseData.user_data;
            this.userId = this.responseData.user_id;
            localStorage.setItem('userData', JSON.stringify(userDeatil));
            loading.dismiss();
            this.navCtrl
              .push(TabsPage)
              .then(() => {
                const index = this.viewCtrl.index;
                this.navCtrl.remove(index);
              });
            // this.navCtrl.push(TabsPage);
          } else {
            this.message = this.responseData.message;
            loading.dismiss();
            let toast = this.toastCtrl.create({
              message: this.message,
              duration: 2000,
              position: 'bottom'
            });
            toast.present(toast);
          }
      }, (err) => {
        loading.dismiss();
        console.log("Error", err);
        let toast = this.toastCtrl.create({
          message: err,
          duration: 2000,
          position: 'bottom'
        });
        toast.present(toast);
      });
  }    

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>     

package.json

{
  "name": "sujagSindhiSamiti",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/core": "4.20.0",
    "@ionic-native/splash-screen": "4.20.0",
    "@ionic-native/status-bar": "4.20.0",
    "@ionic/storage": "2.2.0",
    "cordova-android": "^8.1.0",
    "ionic-angular": "3.9.9",
    "ionicons": "3.0.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.29"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.4",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.1.3",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "typescript": "2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-ionic-keyboard": {}
    },
    "platforms": [
      "android"
    ]
  }
}
Augustin R
  • 7,089
  • 3
  • 26
  • 54
Unnati Patadia
  • 662
  • 3
  • 19
  • 39

2 Answers2

0

Did you add network_security_config.xml path and usesCleartextTraffic your config.xml under platform android something like this:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
  <application android:networkSecurityConfig="@xml/network_security_config" />
  <application android:usesCleartextTraffic="true"/>
</edit-config>
Najam Us Saqib
  • 3,190
  • 1
  • 24
  • 43
hasim
  • 13
  • 1
  • 3
0

Change the line it should work

    this.responseData = result;

    this.responseData = JSON.parse(result);
            OR 
    this.responseData = JSON.stringify(result);
Jatin Devani
  • 194
  • 2
  • 7
  • I didn't get any response. it returns an error at `err => { console.log("Error", err); reject(err); }` in postData(credentials, type) function – Unnati Patadia Jan 24 '20 at 04:47