2017-12-30 7 views
-1

공유 환경 설정에 저장된 숫자를 사용하여 문자 메시지를 보내지 만 응용 프로그램을 실행할 때 충돌이 발생하고 logcat에 불법 목적지 주소가 표시된다고합니다? 여기 불법 목적지 주소 sms manager 공유 환경 설정

MainActivity.java 내 로그 캣

12-30 21:01:30.758 12239-12239/? E/AndroidRuntime: FATAL EXCEPTION: main 
               Process: com.android.beez.help2, PID: 12239 
               java.lang.IllegalArgumentException: Invalid destinationAddress 
                at android.telephony.SmsManager.sendTextMessage(SmsManager.java:127) 
                at com.android.beez.help2.MainActivity.sendSms(MainActivity.java:63) 
                at com.android.beez.help2.MainActivity$2.onClick(MainActivity.java:41) 
                at android.view.View.performClick(View.java:4475) 
                at android.view.View$PerformClick.run(View.java:18790) 
                at android.os.Handler.handleCallback(Handler.java:808) 
                at android.os.Handler.dispatchMessage(Handler.java:103) 
                at android.os.Looper.loop(Looper.java:193) 
                at android.app.ActivityThread.main(ActivityThread.java:5328) 
                at java.lang.reflect.Method.invokeNative(Native Method) 
                at java.lang.reflect.Method.invoke(Method.java:515) 
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
                at dalvik.system.NativeStart.main(Native Method) 

이며, 여기

package com.android.beez.help2; 

import android.app.Service; 
import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.location.LocationManager; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.telephony.SmsManager; 
import android.view.View; 
import android.widget.Button; 

public class MainActivity extends AppCompatActivity { 
Button button; 
SharedPreferences sharedPreferences; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    buttonInit(); 
    Button setupMa = (Button) findViewById(R.id.setupMA); 
    setupMa.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent a = new Intent(MainActivity.this,Setup.class); 
      startActivity(a); 
     } 
    }); 


    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      loadCredit(); 
      sendSms(); 

     } 
    }); 
} 


protected void sendSms() { 

    spInit(); 

    String number1 = sharedPreferences.getString("first", ""); 
    String number2 = sharedPreferences.getString("second", ""); 
    String number3 = sharedPreferences.getString("third", ""); 
    String name = sharedPreferences.getString("name", ""); 
    String text = "Help, this is " + name + ", if you are reading this I am in trouble please help me" + 
      " Iam located at " + "http://www.google.com/maps/place/"+GPSTracker.latitude+","+GPSTracker.longitude+ " " + 
      "" + 
      "" + 
      "-Sent via the Emergency App"; 

    SmsManager manager = SmsManager.getDefault(); 
    manager.sendTextMessage(number1, null, text, null, null); 
    manager.sendTextMessage(number2, null, text, null, null); 
    manager.sendTextMessage(number3, null, text, null, null); 



    boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE) 
      .getBoolean("isFirstRun", true); 

    if (isFirstRun) { 
     Intent launchSetups = new Intent(MainActivity.this, Setup.class); 
     startActivity(launchSetups); 


     } 
    } 

protected void loadCredit() { 

    spInit(); 

    String creditLine = sharedPreferences.getString("dialLoadSp",""); 

    Uri number = Uri.parse("tel:"+creditLine); 
    Intent callIntent = new Intent(Intent.ACTION_DIAL, number); 
    startActivity(callIntent); 
} 

public void buttonInit() { 
    button = (Button) findViewById(R.id.button_main); 
} 
public void spInit() { 
    sharedPreferences = MainActivity.this.getSharedPreferences("com.android.beez.help2",MODE_PRIVATE); 

} 

} 

메시지가 editTexts 출신에 전송하고 있습니다되고있다 숫자 sharedPreferences에 포함됩니다. ... 문제는 공유 환경에서 일하거나 텍스트 관리자

+0

u는 어떤 공간이 있는지를 확인 했습니까? –

+0

@ Md.ibrahimkhalil 어떤 공간? – TheRealBeez

답변

0

난 당신이 destination address 추가는 IF를 지정해야한다고 생각의 문제는 수 if(num1!="" || num2!="" || num3...) manager.sendText...

+0

대상 주소가 지정됩니다. 그것의 숫자는 공유 환경 설정에 저장된 저장됩니다 – TheRealBeez

+0

다음 SMS를 보내기 전에 확인 ... –