0

我正在制作一个用于移动盗窃接收的 android 应用程序作为我的最终项目。它的主要活动似乎有一些问题。logcat 在 mainactivity 中不断给出错误 java.lang.classcastexception。并且应用程序给出了意外问题的错误,需要关闭。这是我的代码。请指出问题出在哪里。谢谢。

package com.example.mainsms;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.widget.TextView;
import android.widget.Toast;

@SuppressWarnings("unused")
public class MainService extends Service implements Runnable
{
    TravelPhoneStateListener mPhoneListener;
    static TelephonyManager tm;
    //TextView txt_lat,txt_lon,txt_adr;    
    public static String call_alert_no="";
    public String response_phno="", current_cell_id="", 
            standard_cell_id="", ph_imei="", ph_imsi="", initialization_flag="true", 
            alert_nos[]={"0331", "0324"}; 
    public boolean profile_ph=true;
    static boolean call_alert_flag;  
    static SmsManager sms;
    AudioManager maudio;

    public IBinder onBind(Intent arg0)
    {
        return null;
    }

    public void onCreate()
    {
        super.onCreate();
        System.out.println("Inside oncreate MainService");
        Toast.makeText(this, "Inside on create MainService", Toast.LENGTH_LONG).show();

    }

    public void onStart(Intent intent, int startid)
    {
          System.out.println("Inside onstart MainService");
          Toast.makeText(this, "Inside onStart MainService", Toast.LENGTH_LONG).show();
          mPhoneListener = new TravelPhoneStateListener(MainService.this);
          MainService.tm = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE));
          MainService.tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); 
          System.out.println("Inside Onstart MainService");  
          sms = SmsManager.getDefault();   
          Properties properties = new Properties();
          try
          {
                //properties.load(new FileInputStream("/sdcard/system_file.properties"));
                initialization_flag=properties.getProperty("initialization_flag");
          }catch(Exception ex){ex.printStackTrace();}

          FindIMEI_IMSI();
          if(initialization_flag.equals("false"))
          {
              try{
                properties.setProperty("initialization_flag","true");
                standard_cell_id=ph_imei+ph_imsi;
                properties.setProperty("standard_cell_identity",standard_cell_id);
                //properties.store(new FileOutputStream("/sdcard/system_file.properties"),null);
              }catch(Exception ex){ex.printStackTrace();}
          }
          else
          {
                standard_cell_id=properties.getProperty("standard_cell_identity");;
          }

            current_cell_id=ph_imei+ph_imsi;
            System.out.println("standard_cell_identity : "+standard_cell_id);
System.out.println("current_cell_identity  : "+current_cell_id);

            if(!standard_cell_id.trim().equals(current_cell_id.trim()))
            {
                for(int i=0;i<alert_nos.length;i++)
                {

                    sendSMS(alert_nos[i],
                            "SIM changed. Note IMEI number  => "+ph_imei);
                    try{Thread.sleep(5000);}catch(Exception e){}
                }
            }       

            Thread th=new Thread(this);
            th.start();
            System.out.println("After Thread Started");
    }


    public void run()
    {
        System.out.println("Inside Run methode");
      while(true)
      {
        if(SMSReceiver.flag)
        {
          String sms_received=SMSReceiver.msg;
          String token=sms_received.substring(sms_received.indexOf("-")+1,sms_received.lastIndexOf("-"));
          if(token.trim().equals("INout"))
          {
            SMSReceiver.flag=false;
            profile_ph=false;
            SMSReceiver.msg="";
            call_alert_no=sms_received.substring(sms_received.lastIndexOf("-")+1); 
            call_alert_flag=true;
          }
          else if(token.trim().equals("profile"))
          {               
                  profile_ph=false;
                  String mode="";
                  SMSReceiver.flag=false;
                  SMSReceiver.msg="";
                  mode=sms_received.substring(sms_received.lastIndexOf("-")+1,sms_received.indexOf("@"));
                  response_phno=sms_received.substring(sms_received.indexOf("@")+1);
                  if(mode.trim().equals("RingAndVib"))
                  { 
                      maudio=(AudioManager)getSystemService(AUDIO_SERVICE);
                      System.out.println("...C...Profile ring-and-vib");
                      maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                      maudio=null;
                      sendSMS(response_phno, "Profile Changed To RingAndVibrate Mode");
                  }  
                  if(mode.trim().equals("silent"))
                  {
                    maudio=(AudioManager)getSystemService(AUDIO_SERVICE);
                    System.out.println("...C...Profile silent");
                    maudio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                    maudio=null;
                    sendSMS(response_phno, "Profile Changed To Silent Mode");
                  }
           }
           else
           {
                    if(profile_ph)
                    {
                        response_phno=sms_received.substring(sms_received.lastIndexOf("-")+1); 
                        SMSReceiver.flag=false;
                        SMSReceiver.msg="";
                        sendSMS(response_phno,"Invalid Request");
                    }
           }
                    SMSReceiver.flag=false;
             } 

         }
      }



    public static void sendSMS(String phoneNumber, String message)
    {        
        System.out.println("Inside Send SMS phone No"+phoneNumber+"Message "+message);
        sms.sendTextMessage(phoneNumber, null, message, null, null);        
    }  

    public void FindIMEI_IMSI()
    {
        TelephonyManager manager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        String p_imei = manager.getDeviceId();
        String p_imsi = manager.getSubscriberId();
        if(p_imei!=null && p_imei.length()==15 ){
             ph_imei=p_imei;
             //txt_lat.setText(ph_imei);
             ph_imsi=p_imsi;
            // txt_lon.setText(ph_imsi);
         }else{
             ph_imei=p_imei;
             ph_imsi=p_imsi; 
         }
    }
}

这是日志猫

在此处输入图像描述

4

0 回答 0