应用程序不适用于早期版本的android

时间:2013-07-11 15:15:21

标签: android versioning

我遇到了我开发的应用程序的问题。问题是APP正在为Android 4.1工作,但不适用于android 2.3.7。

manifest.xml中的min SDK值设置为8.

当我调试时,我发现在执行setContentView时失败了(R.layout.activity_uniflow_results);方法

附件是我的AndroidManifest.xml和失败的JAVA。

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gasguirre.MobilePumpApp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.gasguirre.MobilePumpApp.Main"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.gasguirre.MobilePumpApp.Uniflow"
            android:label="@string/title_activity_uniflow"
            android:parentActivityName="com.example.prueba1.Main" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.prueba1.Main" />
        </activity>
        <activity
            android:name="com.gasguirre.MobilePumpApp.Multiflow"
            android:label="@string/title_activity_multiflow"
            android:parentActivityName="com.example.prueba1.Main" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.prueba1.Main" />
        </activity>
        <activity android:name="com.gasguirre.MobilePumpApp.Uniflow_results"/>
        <activity android:name="com.gasguirre.MobilePumpApp.Multiflow_results"/>
    </application>
</manifest>

Uniflow_results.java

package com.gasguirre.MobilePumpApp;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.util.Date;


public class Uniflow_results extends Activity {


Date d = new Date();
   CharSequence datetime  = DateFormat.format("yyyy-MM-dd hh:mm:ss", d.getTime());

    String[] emailRecipient = {""};
    private double  volume_result_a = 0.0;
    private double  volume_result_b = 0.0;
    private double  volume_result_c = 0.0;
    private double  volume_result_d = 0.0;
    DecimalFormat df = new DecimalFormat("#.##");
    private double drug_a_quantity = 0.0;
    private double drug_b_quantity = 0.0;
    private double drug_c_quantity = 0.0;
    private double drug_d_quantity = 0.0;
    private double volume_saline= 0.0;


    private double drug_a_concentration = 0.0;
    private double drug_b_concentration = 0.0;
    private double drug_c_concentration = 0.0;
    private double drug_d_concentration = 0.0;
    int counter = 1;
    TextView volume_drugA;
    TextView volume_drugB;
    TextView volume_drugC;
    TextView volume_drugD;
    TextView volume_salineTextView;

    TextView name_drugA;
    TextView name_drugB;
    TextView name_drugC;
    TextView name_drugD;

    String pump_model = "N/A";
    String drug_a_name = "Drug A";
    String drug_b_name = "Drug B";
    String drug_c_name = "Drug C";
    String drug_d_name = "Drug D";

    String unit_type = "";
    String unit_type2 = "";
    private double pump_flow = 0.0;
    private double reservoir_volume = 0.0;

    EditText patient_nameET;

    Button send_report;


    private void retrieve_variables() {
        Bundle extras = getIntent().getExtras();

        unit_type2  = extras.getString("unit_type2");
        unit_type = extras.getString("unit_type1");

        if (extras.getDouble("pump_flow") > 0) {
           pump_flow = extras.getDouble("pump_flow");
        }

        if (extras.getDouble("reservoir_volume_edit_text") > 0) {
           reservoir_volume = extras.getDouble("reservoir_volume_edit_text");
        }

        //chequea si extras está vacio, y pone el valor que se pasó de la actividad anterior.

            volume_result_a = extras.getDouble("volume_a");
            volume_result_b = extras.getDouble("volume_b");
            volume_result_c = extras.getDouble("volume_c");
            volume_result_d = extras.getDouble("volume_d");

        drug_a_quantity = extras.getDouble("drug_a_quantity");
        drug_b_quantity = extras.getDouble("drug_b_quantity");
        drug_c_quantity = extras.getDouble("drug_c_quantity");
        drug_d_quantity = extras.getDouble("drug_d_quantity");

        drug_a_concentration = extras.getDouble("drug_a_concentration");
        drug_b_concentration = extras.getDouble("drug_b_concentration");
        drug_c_concentration = extras.getDouble("drug_c_concentration");
        drug_d_concentration = extras.getDouble("drug_d_concentration");


            if (extras.getString("drug_a_name") != null) {
                drug_a_name = extras.getString("drug_a_name");
            }

            if (extras.getString("drug_b_name") != null) {
                drug_b_name = extras.getString("drug_b_name");
            }

            if (extras.getString("drug_c_name") != null) {
                drug_c_name = extras.getString("drug_c_name");
            }
            if (extras.getString("drug_d_name") != null) {
                drug_d_name = extras.getString("drug_d_name");
            }

        if (extras.getString("pump_model") != null) {
            pump_model = extras.getString("pump_model");
        }
        if (reservoir_volume != 0)
        {
        volume_saline = reservoir_volume - (volume_result_a +volume_result_b  +volume_result_c + volume_result_d);
        }
    }

private  void  populate_labels(){

    volume_drugA.setText(String.format("%.02f", volume_result_a));
    volume_drugB.setText(String.format("%.02f", volume_result_b));
    volume_drugC.setText(String.format("%.02f", volume_result_c));
    volume_drugD.setText(String.format("%.02f", volume_result_d));

    volume_salineTextView.setText(String.format("%.02f", volume_saline));

    name_drugA.setText(drug_a_name);
    name_drugB.setText(drug_b_name);
    name_drugC.setText(drug_c_name);
    name_drugD.setText(drug_d_name);
}

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uniflow_results);

        volume_drugA = (TextView) findViewById(R.id.volume_drugA);
        volume_drugB = (TextView) findViewById(R.id.volume_drugB);
        volume_drugC = (TextView) findViewById(R.id.volume_drugC);
        volume_drugD = (TextView) findViewById(R.id.volume_drugD);

        name_drugA = (TextView) findViewById(R.id.name_drug_A_textView);
        name_drugB = (TextView) findViewById(R.id.name_drug_B_textView);
        name_drugC = (TextView) findViewById(R.id.name_drug_C_textView);
        name_drugD = (TextView) findViewById(R.id.name_drug_D_textView);
        volume_salineTextView = (TextView) findViewById(R.id.volume_salineTextView);
        retrieve_variables();
        populate_labels();

        addListenerOnButton();

    }

    private void addListenerOnButton() {
        send_report = (Button) findViewById(R.id.send_report_button);

        send_report.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        patient_nameET = (EditText) findViewById(R.id.patient_name_edit_text);

                        if (unit_type.equals("ug")){
                            drug_a_quantity = drug_a_quantity * 1000;
                            drug_b_quantity = drug_b_quantity * 1000;
                            drug_c_quantity = drug_c_quantity * 1000;
                            drug_d_quantity = drug_d_quantity * 1000;
                            }
                        if (unit_type2.equals("ug/ml")){
                            drug_a_concentration = drug_a_concentration * 1000;
                            drug_b_concentration = drug_b_concentration * 1000;
                            drug_c_concentration = drug_c_concentration * 1000;
                            drug_d_concentration = drug_d_concentration * 1000;
                        }

                        sendEmail();

                    }

        });
    }

    private void sendEmail() {
        getEmailInfo();

       // String to = email_address;
        String subject = ("Report for Patient: " + patient_nameET.getText().toString() + " from Mobile Pump App");
        String text_report =

               ("Patient Name: " +  patient_nameET.getText().toString() +'\n' +
                "Report generated on: " + datetime + '\n' +
                "Protocol number: " + counter + '\n' + '\n' +
                "Volume of "+ drug_a_name + ": " + volume_drugA.getText().toString() + " ml" + '\n' +
                "Volume of "+ drug_b_name + ": " + volume_drugB.getText().toString() + " ml" + '\n' +
                "Volume of "+ drug_c_name + ": " + volume_drugC.getText().toString() + " ml" + '\n' +
                "Volume of "+ drug_d_name + ": " + volume_drugD.getText().toString() + " ml" + '\n' +
                "Volume of Sterile Saline solution to add: " + df.format(volume_saline) + " ml" + '\n' + '\n'
                      +

               "ENTRY VALUES" + '\n' + '\n'+

                       "Pump Model: " + pump_model + '\n' +
                       "Pump Flow (ml/24h): " + df.format(pump_flow) + '\n' +
                       drug_a_name + "- Quantity: " + df.format(drug_a_quantity) + " "+ unit_type + " - Concentration: " + df.format(drug_a_concentration) +  unit_type2 +'\n' +
                       drug_b_name + "- Quantity: " + df.format(drug_b_quantity) + " "+ unit_type + " - Concentration: " + df.format(drug_b_concentration) +  unit_type2 +'\n' +
                       drug_c_name + "- Quantity: " + df.format(drug_c_quantity) + " "+ unit_type + " - Concentration: " + df.format(drug_c_concentration) +  unit_type2 +'\n' +
                       drug_d_name + "- Quantity: " + df.format(drug_d_quantity) + " "+ unit_type + " - Concentration: " + df.format(drug_d_concentration) +  unit_type2 +'\n' +
                       "Reservoir Volume: " + df.format(reservoir_volume) + '\n'
               );


        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.putExtra(Intent.EXTRA_EMAIL, emailRecipient);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, text_report);
        emailIntent.setType("message/rfc822");

        startActivity(Intent.createChooser(emailIntent, "Email"));
    }


    private void getEmailInfo() {
        SharedPreferences preferences = getSharedPreferences("preferences", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
           String email = preferences.getString("email","");
           emailRecipient = email.split(",");
           counter = preferences.getInt("counter", 1 );
           counter = counter +1;
           editor.putInt("counter", counter);
           editor.commit();
       }

    public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
           }





       public boolean onOptionsItemSelected(MenuItem item){
           super.onOptionsItemSelected(item);
           switch (item.getItemId()){
               case R.id.setEmail:
                   setEmail();
                   break;

           }
       return true;
       }
       public void setEmail(){
           AlertDialog.Builder alert = new AlertDialog.Builder(this);

           alert.setTitle("Set E-Mail");


           // Set an EditText view to get user input
           final EditText input = new EditText(this);
           alert.setView(input);

           alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int whichButton) {
             String email = input.getText().toString();

               SharedPreferences preferences = getSharedPreferences("preferences",Context.MODE_PRIVATE);
               SharedPreferences.Editor editor = preferences.edit();
               editor.putString("email", email);
               editor.commit();
             }
           });
           alert.setMessage("You can set more than one recipient by separating e-mail with a comma  e.g. email@email.com, email2@email.com");
           alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int whichButton) {
               // Canceled.
             }
           });

       alert.show();

       }


}

Activity_uniflow_results.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              tools:context=".Uniflow_results">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="@string/set_values"
            android:id="@+id/textView2"
            android:layout_gravity="center"/>

    <Space
            android:layout_width="23dp"
            android:layout_height="23dp"
            android:layout_gravity="center"
            android:id="@+id/space"/>

    <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/volume"
                android:id="@+id/textView"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="2dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/name_drug_A"
                android:id="@+id/name_drug_A_textView"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="10dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/volume_drugA"
                android:id="@+id/volume_drugA"
                android:layout_gravity="center_horizontal|top"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/units_label3"
                android:id="@+id/textView3"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginLeft="2dp"/>
    </TableRow>

    <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:id="@+id/tableRow">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/volume"
                android:id="@+id/textView4"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="2dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/name_drug_B"
                android:id="@+id/name_drug_B_textView"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="10dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/volume_drugA"
                android:id="@+id/volume_drugB"
                android:layout_gravity="center_horizontal|top"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/units_label3"
                android:id="@+id/textView6"
                android:layout_marginLeft="2dp"
                android:layout_gravity="center_horizontal|top"/>
    </TableRow>

    <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:id="@+id/tableRow2">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/volume"
                android:id="@+id/textView7"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="2dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/name_drug_C"
                android:id="@+id/name_drug_C_textView"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="10dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/volume_drugA"
                android:id="@+id/volume_drugC"
                android:layout_gravity="center_horizontal|top"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/units_label3"
                android:id="@+id/textView9"
                android:layout_marginLeft="2dp"
                android:layout_gravity="center_horizontal|top"/>
    </TableRow>

    <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:id="@+id/tableRow3">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/volume"
                android:id="@+id/textView10"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="2dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/name_drug_D"
                android:id="@+id/name_drug_D_textView"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="10dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/volume_drugA"
                android:id="@+id/volume_drugD"
                android:layout_gravity="center_horizontal|top"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/units_label3"
                android:id="@+id/textView11"
                android:layout_marginLeft="2dp"
                android:layout_gravity="center_horizontal|top"/>
    </TableRow>

    <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:id="@+id/tableRow4">

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/volume_saline"
                android:id="@+id/textView12"
                android:layout_gravity="center_horizontal|top"
                android:layout_marginRight="10dp"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/volume_drugA"
                android:id="@+id/volume_salineTextView"
                android:layout_gravity="center_horizontal|top"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/units_label3"
                android:id="@+id/textView15"
                android:layout_marginLeft="2dp"
                android:layout_gravity="center_horizontal|top"/>
    </TableRow>

    <Space
            android:layout_width="31dp"
            android:layout_height="40dp"
            android:layout_gravity="center"/>

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="@string/reporting"
            android:id="@+id/textView5"
            android:layout_gravity="center"/>

    <Space
            android:layout_width="23dp"
            android:layout_height="23dp"
            android:layout_gravity="center"
            android:id="@+id/space2"/>

    <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/patient_name"
                android:id="@+id/textView8"
                android:layout_gravity="center"/>

        <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:ems="10"
                android:id="@+id/patient_name_edit_text"
                android:hint="Name"/>

    </TableRow>

    <Space
            android:layout_width="24dp"
            android:layout_height="46dp"
            android:layout_gravity="center"
            android:id="@+id/space3"/>

    <Button
            android:layout_width="184dp"
            android:layout_height="wrap_content"
            android:text="@string/send_report"
            android:id="@+id/send_report_button"
            android:layout_gravity="center"/>

</LinearLayout>
    </ScrollView>

奇怪的是,在第一个活动中使用了setContentView方法,但是没有在那里失败,在第二个活动中使GUI膨胀时失败

1 个答案:

答案 0 :(得分:2)

API 14中添加了

Space,因此在Gingerbread设备上不可用。您可以使用View

<View
    android:layout_width="23dp"
    android:layout_height="23dp"
    android:layout_gravity="center"
    android:id="@+id/space2"/>

或者将support-library-v7(注意:不是v4)添加到您的项目中,该项目包含Space的反向移植版本:

<android.support.v7.widget.Space
    android:layout_width="23dp"
    android:layout_height="23dp"
    android:layout_gravity="center"
    android:id="@+id/space2"/>