简体   繁体   English

如何升级android java项目

[英]How to upgrade android java project

I've an old android project (Java) which was made around 5 years ago by another java developer and now i need to upgrade this project but i am a web developer so i can't deal with java project.我有一个旧的 android 项目(Java),它是大约 5 年前由另一个 java 开发人员创建的,现在我需要升级这个项目,但我是一名 web 开发人员,所以我无法处理 java 项目。 I can build it with android studio v4.2.2 but i receive Notes:我可以用 android studio v4.2.2 构建它,但我收到注释:

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

and some functions not work on real device (The app crashes and close)和一些功能在真实设备上不起作用(应用程序崩溃并关闭)

My question is how to upgrade this project and make sure its not used a deprecated API?我的问题是如何升级这个项目并确保它没有使用过时的 API?

I am ready for any clarification or code sending.我准备好进行任何澄清或发送代码。

MichaelAttendanceApp.java : MichaelAttendanceApp.java :

package com.michael.attendanceapp;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;

import android.content.DialogInterface;
import android.content.Intent;

import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;

import android.view.View;
import android.widget.Toast;


public class MichaelAttendanceApp extends Activity {
//  /** Called when the activity is first created. */

    static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
    private final Class_GetData GD = new Class_GetData();
    private final Class_ArrangeCall arrange = new Class_ArrangeCall();
    ProgressDialog pDialog;
    String [][] AttendanceData;
    private AsyncTask<Void, Void, Void> mTask;
    String reply ="";
    int AttendanceRowsCount = 0;
    
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }



    public void scanQR(View v) {
        try {
            Intent intent = new Intent(ACTION_SCAN);
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            startActivityForResult(intent, 0);
        } catch (ActivityNotFoundException anfe) {
            showDialog(MichaelAttendanceApp.this, "No Scanner Found", "Download a scanner code activity?", "Yes", "No").show();
        }
    }
    
    
    public void syncAttendance(View v) {
        try
        {
//      /** Retrieving data from database **/
        //use cursor to keep all data
        //cursor can keep data of any data type
         AttendanceData=GD.GetAttendance(MichaelAttendanceApp.this);
         AttendanceRowsCount = AttendanceData.length;

         if (AttendanceRowsCount > 0)
         {
             mTask = new GetDataFromServer().execute();
         }else
         {
             Toast toast = Toast.makeText(this, "No records found ..", Toast.LENGTH_LONG);
             toast.show();
         }
        
        
//      /** show confirmation toast **/
        //Toast toast = Toast.makeText(this, "Synchronization Completed", Toast.LENGTH_LONG);
        //toast.show();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        
    }
    
    
     private class GetDataFromServer extends AsyncTask<Void, Void, Void> {
         
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Showing progress dialog
                pDialog = new ProgressDialog(MichaelAttendanceApp.this);
                pDialog.setMessage("Please wait...");
                pDialog.setCancelable(false);
                pDialog.show();
            }
     
            @Override
            protected Void doInBackground(Void... arg0) {
                for(int i =0;i<AttendanceData.length;i++)
                {
                    
                        
                        String param3 = AttendanceData[i][0] + "/"+(AttendanceData[i][1]).toString().replace(" ", "%20")+"/"+AttendanceData[i][2]+"/"+AttendanceData[i][3]+"/"+AttendanceData[i][4];
                         reply = arrange.ArrangeCall("scan_qr", 1, param3, MichaelAttendanceApp.this);
                        if (reply.equals(""))
                        {
                            GD.UpdateAttendance(MichaelAttendanceApp.this, Integer.parseInt(AttendanceData[i][0]), AttendanceData[i][1], AttendanceData[i][2], AttendanceData[i][3], AttendanceData[i][4]);
                        }else
                        {
                           break;
                            
                        }
                }
                return null;
            }
     
            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                // Dismiss the progress dialog
                if (pDialog.isShowing())
                    pDialog.dismiss();
                GD.DeleteAttendance(MichaelAttendanceApp.this);
               
                if(reply.equals(""))
                {
                    Toast.makeText(MichaelAttendanceApp.this,"Upload Done" , Toast.LENGTH_LONG).show();
                }else
                {
                     Toast.makeText(MichaelAttendanceApp.this,reply , Toast.LENGTH_LONG).show();
                }
                    
                }
            }
    

    private static AlertDialog showDialog(final Activity act, CharSequence title, CharSequence message, CharSequence buttonYes, CharSequence buttonNo) {
        AlertDialog.Builder downloadDialog = new AlertDialog.Builder(act);
        downloadDialog.setTitle(title);
        downloadDialog.setMessage(message);
        downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                Uri uri = Uri.parse("market://search?q=pname:" + "com.google.zxing.client.android");
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                try {
                    act.startActivity(intent);
                } catch (ActivityNotFoundException anfe) {

                }
            }
        });
        downloadDialog.setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
            }
        });
        return downloadDialog.show();
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String memID = intent.getStringExtra("SCAN_RESULT");
//              /** String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); **/

//              /** get current time and the day of week **/
                Calendar cc = Calendar.getInstance();
                SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
                String currTime = sdf.format(cc.getTime());
                
//              /** get the day of the week number **/
                int day = cc.get(Calendar.DAY_OF_WEEK);
                
                
//              /** convert the number of the day to the day name **/
                String dayName = "";
                 if(day == 2){
                        dayName = "Mon";
                    } else if (day==3){
                        dayName = "Tue";
                    } else if (day==4){
                        dayName = "Wed";
                    } else if (day==5){
                        dayName = "Thu";
                    } else if (day==6){
                        dayName = "Fri";
                    } else if (day==7){
                        dayName = "Sat";
                    } else if (day==1){
                        dayName = "Sun";
                    }
                
                
                 //get Member ID from the URl [last 6 char]
                 //int URLLenght = memID.length();
                 
                 //for ma7abawy
                 //int ID=Integer.parseInt(memID.substring(URLLenght-6, URLLenght));
                 int ID=Integer.parseInt(memID);
                 
                    int mYear = cc.get(Calendar.YEAR);
                    int mMonth = cc.get(Calendar.MONTH) + 1;
                    int mDay = cc.get(Calendar.DAY_OF_MONTH);

                //textView.setText(""+mDay+"/"+mMonth+"/"+mYear);
                 
                 String Sdate = ""+mYear+"-"+mMonth+"-"+mDay;
                 
                 String Activity = "Ma7abawy";
                 //for MASA
//                insert data into able **/
               GD.InsertAttendance(MichaelAttendanceApp.this,ID, currTime, dayName, Sdate, Activity);
                
//              show confirmation toast
//              Toast toastt = Toast.makeText(this, Sdate, Toast.LENGTH_LONG);
//              toastt.show();
               
                Toast toast = Toast.makeText(this, "Done", Toast.LENGTH_LONG);
                toast.show();
                
//              /** return to scanning activity **/
                this.scanQR(null);
            }
        }
    }
}

It crashes Here : public void onActivityResult它在这里崩溃: public void onActivityResult

The note is very unlikely to be the cause of the error.该注释不太可能是导致错误的原因。

For instance using a List without generic type causes it.例如,使用没有泛型类型的List会导致它。

List strings = new ArrayList();

vs对比

List<String> strings = new ArrayList();

In that particular case adding the <String> part will be enough for the note to disappear, but your code will still fail.在这种特殊情况下,添加<String>部分足以让注释消失,但您的代码仍然会失败。

You're going to have to debug the app to know the cause of the crashes.您将不得不调试应用程序以了解崩溃的原因。

请分享完整的崩溃日志,以便我们确定确切的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM