Приложение работает на некоторых телефонах, а не на других - PullRequest
0 голосов
/ 06 мая 2018

Приложение, над которым я работал в течение достаточно долгого времени, похоже, работает на моем телефоне, но когда я устанавливаю его на другие телефоны, оно либо отображается должным образом, отображается частично, либо для некоторых не открывается вообще. причина. Я проверил манифест:

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme">
    <activity android:name=".activities.Checkbox">
    </activity>
    <activity android:name=".activities.InputActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".activities.ReviewActivity">
    </activity>
</application>

Обратите внимание, что уровень API на моем телефоне 27, он работает, я пробовал на других телефонах Android 8, на некоторых работает, на некоторых работает частично (см. Рисунок ниже, кнопка отсутствует), а на некоторых телефонах приложение открывается, на секунду или две пустое, а затем закрывается.

Что вы обычно должны иметь на первом занятии:

enter image description here

Что находится на Huawei P9 (см. Отсутствующую кнопку):

enter image description here

И на других телефонах приложение устанавливается, но просто не показывает первую активность и закрывается через несколько секунд без сбоев.

Вот код XML для первого действия:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_10">

<View
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:background="@color/colorPrimary" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:orientation="vertical"
    android:padding="@dimen/spacing_mlarge">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/spacing_middle"
        android:visibility="visible"
        app:cardCornerRadius="6dp"
        app:cardElevation="5dp">
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="@dimen/spacing_mlarge">

            <TextView
                android:id="@+id/input_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="@dimen/spacing_xlarge"
                android:layout_marginTop="@dimen/spacing_middle"
                android:text="Bienvenue sur MBTouch!"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/green_500"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Numéro d'identification:"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_identif"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Date de naissance (jj/mm/aaaa):"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_naiss"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="date"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Poids (kg.g) (ex: 84.2):"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_poids"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Taille (m.cm) (ex: 1.82):"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_taille"
                android:layout_width="match_parent"
                android:inputType="numberDecimal"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textColor="@color/blue_600"
                android:theme="@style/EditText.Grey" />

            <Button
                android:id="@+id/input_start"
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:onClick="onContinue"
                android:layout_marginLeft="-4dp"
                android:layout_marginRight="-4dp"
                android:background="@drawable/btn_rounded_primary"
                android:text="Commencer"
                android:textAllCaps="false"
                android:textColor="@android:color/white"
                android:textStyle="bold" />

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/spacing_mlarge" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Application conçue par S.C. iNeedHelp S.R.L."
                android:gravity="center_horizontal"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="On vous attend sur https://ineedhelp.be/ !"
                android:gravity="center_horizontal"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            <ImageView
                android:layout_width="180dp"
                android:layout_height="60dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="@dimen/spacing_mlarge"
                android:layout_marginTop="@dimen/spacing_large"
                android:src="@drawable/ineedhelp"/>

        </LinearLayout>
        </ScrollView>
    </android.support.v7.widget.CardView>

    <View
        android:layout_width="0dp"
        android:layout_height="@dimen/spacing_large" />

</LinearLayout>

А вот Java для первого действия:

открытый класс InputActivity расширяет AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.activity_input);
}

public void onContinue(View v){
    EditText i = (EditText) findViewById(R.id.input_identif);
    EditText d = (EditText) findViewById(R.id.input_naiss);
    EditText p = (EditText) findViewById(R.id.input_poids);
    EditText t = (EditText) findViewById(R.id.input_taille);

    String ident = i.getText().toString();
    String date = d.getText().toString();
    String poids = p.getText().toString();
    String taille = t.getText().toString();

    if (ident.equals("")) {
        Toast.makeText(getApplicationContext(),"Le numéro d'identification ne peut pas être vide!",
                Toast.LENGTH_SHORT).show();
    } else {
        if (!isValidDate(date)) {
            Toast.makeText(getApplicationContext(),"Veuillez introduire une date au format JJ/MM/AAAA (ex: 12/10/1975).",
                    Toast.LENGTH_SHORT).show();
        } else {
            if(!isValidDouble(poids)){
                Toast.makeText(getApplicationContext(),"Veuillez introduire un nombre (avec un point, pas de virgule) pour le poids (ex: 75.3).",
                        Toast.LENGTH_SHORT).show();
            } else {
                if(!isValidDouble(taille)){
                    Toast.makeText(getApplicationContext(),"Veuillez introduire un nombre (avec un point, pas de virgule) pour la taille (ex: 1.85).",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Double tl = Double.parseDouble(taille.trim());
                    Double po = Double.parseDouble(poids.trim());
                    Intent mIntent = new Intent(this, Checkbox.class);
                    mIntent.putExtra("identification", ident);
                    mIntent.putExtra("date", date);
                    mIntent.putExtra("poids", po.toString());
                    mIntent.putExtra("taille", tl.toString());
                    Double bmi = (po / (tl*tl));
                    mIntent.putExtra("bmi", bmi.toString());
                    Toast.makeText(getApplicationContext(),"BMI: " + bmi.toString(),
                            Toast.LENGTH_SHORT).show();
                    startActivity(mIntent);
                }
            }

        }
    }
}

public boolean isValidDate(String dateString) {
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    try {
        df.parse(dateString);
        return true;
    } catch (ParseException e) {
        return false;
    }
}

public boolean isValidDouble(String number) {
    try {
        Double.parseDouble(number.trim());
    }
    catch(NumberFormatException e){
        return false;
    }
    return true;
}

}

Gradle

применить плагин: 'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "ro.ineedhelp.patientquiz"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // google support library ---------------------------------------------------------------------
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    //noinspection GradleCompatible
    compile 'com.android.support:design:25.4.0'
    compile 'com.android.support:cardview-v7:25.4.0'
    compile 'com.android.support:recyclerview-v7:25.4.0'
    implementation 'com.android.support:appcompat-v7:25.4.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.android.support:support-vector-drawable:25.4.0'

    // third party dependencies -------------------------------------------------------------------
    compile 'com.balysv:material-ripple:1.0.2'                  // ripple effect
    compile 'com.github.bumptech.glide:glide:3.7.0'             // image loader
    compile 'com.wdullaer:materialdatetimepicker:3.2.0'         // date & time picker
    compile 'com.mikhaellopez:circularimageview:3.0.2'          // circle image view
    compile 'com.github.pchmn:MaterialChipsInput:1.0.8'         // material chip
    compile 'com.hootsuite.android:nachos:1.1.1'                // material chips

    testCompile 'com.android.support:appcompat-v7:25.4.0'
}

Как вы думаете, вы знаете, что может вызвать это? Я подписываю APK с подписью Level1 и Level2.

Заранее спасибо.

Ответы [ 4 ]

0 голосов

Ваша кнопка отсутствует на некоторых телефонах, потому что для некоторых телефонов невозможно найти android:background="@drawable/btn_rounded_primary", поэтому ваша кнопка не отсутствует, она просто невидима. Чтобы проверить это, вы должны изменить android:textColor кнопки. Затем убедитесь, что ваш ресурс "@drawable/btn_rounded_primary" находится в правильном каталоге. Мне нужно больше информации, чтобы понять, почему на некоторых телефонах происходит сбой вашего приложения. Не могли бы вы написать мне уровень API этих телефонов?

0 голосов
/ 06 мая 2018

Проверьте sdk версии тех телефонов, на которых приложение не работает. Минимальная версия SDK для вашего приложения - 21, телефоны с версиями SDK ниже 21 не будут поддерживать приложение.

0 голосов
/ 06 мая 2018

Хорошо, поэтому я выяснил, что было не так, по-видимому, некоторым телефонам не нравится опция android:background на кнопках, я убрал ее, и теперь она, кажется, работает правильно.

0 голосов
/ 06 мая 2018

проверьте ваш файл Gradle или структуру проекта. может быть, ваша версия API выше, чем ваше целевое устройство. выберите более низкий API, чтобы решить эту проблему

...