2017-07-05 7 views
-1

GPS位置情報を取得し、関連するメッセージと共にSMS経由で送信する手助けが必要です。私はカスタムメッセージ+ GPS位置を送信する緊急ボタンアプリを開発しました。私はGPSロケーション機能を実装するのに苦労しています。SMSマネージャを使用してSMS位置情報付きのSMSを送信する

GPSなしのオリジナルコード: /このコードfuntcionsだけでなく、それは/

GPSの場所が含まれていませんが
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.telephony.SmsManager; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 

public class MainActivity extends AppCompatActivity { 

    private EditText customMessage; 



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

     customMessage=(EditText)findViewById(R.id.customMessage); 

    } 

    public void sendText(View view) 
    { 


     String message = ""; 
     if (view.getId() == R.id.fab) 
     { 
      message = customMessage.getText().toString(); 
     } 
     else 
     { 
      Button sender = (Button)view; 
      message = sender.getText().toString(); 
     } 
     //Toast.makeText(this, "Test", Toast.LENGTH_SHORT).show(); 

     SmsManager smsManager = SmsManager.getDefault(); 
     smsManager.sendTextMessage("6505551212", null,message + "(Location Here)", null, null); 
    } 


} 

GPS付きコード: /コードの問題は、単にアプリということです私は、送信ボタンをクリックしますが、それはそのMESSAので、作業エラー/

import android.location.Location; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.telephony.SmsManager; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 

public class MainActivity extends AppCompatActivity { 

    private EditText customMessage; 



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

     customMessage=(EditText)findViewById(R.id.customMessage); 

    } 

    public void sendText (View view, String phoneNumber, Location currentLocation) { 

     String message = ""; 
     if (view.getId() == R.id.fab) 
     { 
      message = customMessage.getText().toString(); 
     } 
     else 
     { 
      Button sender = (Button)view; 
      message = sender.getText().toString(); 
     } 


     SmsManager smsManager = SmsManager.getDefault(); 
     StringBuffer smsBody = new StringBuffer(); 
     smsBody.append("http://maps.google.com?q="); 
     smsBody.append(currentLocation.getLatitude()); 
     smsBody.append(","); 
     smsBody.append(currentLocation.getLongitude()); 
     smsManager.sendTextMessage("6505551212", null, smsBody.toString(), null, null); 
    } 
} 
+0

1.クラッシュログを投稿してください。 2.実行時に場所の許可を要求していることを確認してください。 – danypata

+0

あなたはこのライブラリを試すことができます:https://github.com/mcharmas/Android-ReactiveLocation/blob/master/README.mdボタンをクリックして、readmeから最初の例を起動してから、smsにaccuired gps位置: – cYrixmorten

+0

ログ:android.os.Looper.loop(Looper.java:135) とandroid.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(ネイティブメソッド) at java.lang.reflect.Mavod.invoke(Method.java:372) (com.android.internal.os.ZygoteInit)$ MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os。 ZygoteInit.main(ZygoteInit.java:698) 07-05 12:42:21.711 5063-5063 /? I /プロセス:シグナルを送信します。 PID:5063 SIG:9 –

答えて

-1

あなたの前のコードを持っていませんがクラッシュGEの長さは< = 160です。しかし、別のメッセージには、160文字を超えるURLが含まれています。これを克服するには、複数の部分でメッセージを送信する必要があります。以下のコードを使用してください: SmsManager sms = SmsManager.getDefault(); ArrayList<String> parts = sms.divideMessage(messageString); sms.sendMultipartTextMessage(number, null, parts, null, null);

関連する問題