应用程序适用于某些手机而非其他手机

时间:2018-05-06 11:45:31

标签: java android xml crash manifest

我已经工作了很长一段时间的应用程序现在似乎可以在我的手机上工作了,但是当我在其他手机上安装它时,它可以正常显示,部分显示,或者它根本无法打开由于某些原因。我检查了清单:

<!-- 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

华为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;
}

}

摇篮

申请插件:&#39; com.android.application&#39;

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'
}

你认为你知道是什么原因引起的吗?我使用Level1和Level2签名来登录APK。

提前致谢。

4 个答案:

答案 0 :(得分:1)

某些手机上的按钮丢失,因为某些手机无法找到android:background="@drawable/btn_rounded_primary",因此您的按钮不会丢失,只是看不见。要检查这一点,您应该更改按钮的android:textColor。然后检查您的可绘制资源"@drawable/btn_rounded_primary"是否在正确的目录上。 我需要更多信息才能理解,为什么你的应用程序会在某些手机上崩溃。你能写一下这些手机的API等级吗?

答案 1 :(得分:0)

检查您的gradle文件或项目结构。 可能是您的API版本高于目标设备。 选择较低的API可以解决这个问题

答案 2 :(得分:0)

检查应用无效的手机的sdk版本。你的应用程序的最小sdk版本是21,运行低于21的sdk版本的手机不支持该应用程序。

答案 3 :(得分:0)

好吧,所以我弄清楚出了什么问题,显然有些手机不喜欢按钮上的DataFrame选项,我已将其删除,现在它似乎正常工作。