当前位置: 首页 > 知识库问答 >
问题:

如何通过短信发送谷歌地图位置

庾和昶
2023-03-14

如何在SMSManager的文本字符串中分配变量LocationManager?我想发送带有坐标的短信作为文本消息。

Private LocationManager lm;私有LocationListener locationListener;

    lm = (LocationManager) 
            getSystemService(Context.LOCATION_SERVICE);

        locationListener = new MyLocationListener();   

        lm.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 
             0, 
             0, 
            locationListener);
        lm.requestLocationUpdates(

            LocationManager.NETWORK_PROVIDER, 
            0, 
            0, 
            locationListener);


btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
    btnSendSMS.setOnClickListener(new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sendSMS("55565", "coords" );

        }
    });



 private void sendSMS(String phoneNumber, String message) {

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, null, null);
    }

共有1个答案

西门威
2023-03-14

这是我通过电子邮件和短信发送当前位置的代码,希望能有所帮助:)根据需要修改

final LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    final LocationListener mlocListener = new MyLocationListener();

    final Location location = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    updateWithNewLocation(location);
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    mc=mapview.getController();
    mc.setZoom(18);
    mlo=new MyLocationOverlay(this,mapview);
    mapview.getOverlays().add(mlo);
    mapview.invalidate();   
    }




    public class MyLocationListener implements LocationListener

    {

    public void onLocationChanged(final Location location)
    {
        updateWithNewLocation(location);
    }
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

    }

    private void updateWithNewLocation(final Location location)
    {
    mapview=(MapView) findViewById(R.id.map);
    String latLongString;
    TextView myLocationText;
    myLocationText = (TextView)findViewById(R.id.text);
    String addressString = "No address found";

    if ( location != null )
    {
    final double lat = location.getLatitude();
    final double lng = location.getLongitude();

    latLongString = "Lat:" + lat + "\nLong:" + lng;
    final double latitude = location.getLatitude();
    final double longitude = location.getLongitude();
    final Geocoder gc = new Geocoder(this, Locale.getDefault());

    final GeoPoint myLocation = new GeoPoint((int)(lat * 1000000), (int)(lng * 1000000));
    mapview.getController().animateTo(myLocation);
    mapview.getController().setCenter(myLocation);


    try
    {
    final List<Address> addresses = gc.getFromLocation(latitude, longitude, 4);
    final StringBuilder sb = new StringBuilder();
    if ( addresses.size() > 0 )
    {
        final Address address = addresses.get(0);
        for ( int i = 0; i < address.getMaxAddressLineIndex(); i++ )
        {
            sb.append(address.getAddressLine(i)).append("\n");
        }
        sb.append(address.getLocality()).append("\n");
        sb.append(address.getPostalCode()).append("\n");
        sb.append(address.getCountryName());
    }
    addressString = sb.toString();
    }
    catch ( final IOException e )
    {
    }
    }
    else
    {
    latLongString = "No location found";
    }
    myLocationText.setText("Your Current Position is:\n" +
    latLongString + "\n" + addressString);


    }





    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
        MenuInflater inf = getMenuInflater();
        inf.inflate(R.menu.newmenu, menu);
            return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        String tv1; 
        TextView myLocationText;
        myLocationText = (TextView)findViewById(R.id.text);
        tv1= myLocationText.getText().toString(); 
    switch (item.getItemId()) {
    case R.id.msg:

        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.putExtra("sms_body", tv1); 
        sendIntent.setType("vnd.android-dir/mms-sms");
        startActivity(sendIntent); 

    return(true);
    case R.id.email:
        /* Create the Intent */
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        /* Fill it with Data */
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tv1);
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
         return(true);
    }
    return(super.onOptionsItemSelected(item));
    }
 类似资料:
  • 查看:app/views/home/index.html.erb 路线:

  • 为了更熟悉Android编程,我一直在开发一款位置欺骗软件,我注意到我的应用程序似乎不会欺骗谷歌地图。它适用于Facebook和我测试过的其他一些应用程序,但即使关闭了Wifi和GPS,谷歌地图也知道我的确切位置,而不是我伪造的位置。我从Play Store(FakeLocation)下载了另一个欺骗应用,它似乎也没有欺骗谷歌。 这个人似乎也有同样的问题(Android Mock位置不适用于谷歌地

  • 我必须制作一个. net Windows应用程序,通过它我可以通过通过USB连接的Android手机发送短信。在诺基亚手机中,有没有类似于发送短信的代码或API,比如AT命令。我必须通过手机发送短信。也就是说,发送消息时,手机必须通过USB连接。

  • 首先,我使用模拟器来测试这一点。我想用短信文本(作为参数发送)打开默认的SMS应用程序,并允许用户从那里获得控制权(以及内置的应用程序)。我使用以下代码: 当我按下按钮时,什么也没发生。我希望SMS默认应用程序打开,包含用户必须填写的文本和其他字段,然后发送消息。这是因为模拟器还是我的代码?我还在清单中指定了权限:

  • 我正在设计一个应用程序,我想在地图上显示具体的位置。我正在传递地址的,它已经放在上。以下是我的代码.. 但它给了我谷歌地图来获取方向。我知道为什么会这样,因为我在中使用了,但我不知道在特定位置使用什么..请告诉我在那里使用什么..