0

これが原因で何日も苦しんでいます。自動 SMS で GPS データを送信したいのですが、送信できません。変数 lat と logn にアクセスして、sendIntent.putextra.親切に解決策を提案してデータを送信したいです。c2dm を使おうと思ったのですが、遅すぎてメッセージ配信が保証されません。

これがコードです。

public class SendSMSActivity extends Activity {

    Button buttonSend;
    public LocationManager locationManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        buttonSend = (Button) findViewById(R.id.buttonSend);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        locationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER,
                0,
                0,
                MyLocationListener());


        class MyLocationListener implements LocationListener {

            public void onLocationChanged(Location location) {

                String message = String.format(
                        "New Location \n Longitude: %1$s \nLatitude: %2$s",
                        location.getLongitude(), location.getLatitude());
                double lat = location.getLatitude();
                double logn = location.getLongitude();
                Toast.makeText(SendSMSActivity.this, message, Toast.LENGTH_LONG).show();
            }

            public void onStatusChanged(String s, int i, Bundle b) {

                Toast.makeText(SendSMSActivity.this, "Provider status changed",
                        Toast.LENGTH_LONG).show();
            }

            public void onProviderDisabled(String s) {
                Toast.makeText(SendSMSActivity.this,
                        "Provider disabled by the user. GPS turned off",
                        Toast.LENGTH_LONG).show();
            }

            public void onProviderEnabled(String s) {


                Toast.makeText(SendSMSActivity.this,
                        "Provider enabled by the user. GPS turned on",
                        Toast.LENGTH_LONG).show();
            }
        }


        buttonSend.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                try {

                    MyLocationListener obj = new MyLocationListener();


                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                    sendIntent.putExtra("Location Point", lat);
                    sendIntent.putExtra("Location Point", lagn);
                    //  sendIntent.setType("vnd.android-dir/mms-sms");
                    startActivity(sendIntent);

                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(),
                            "SMS faild, please try again later!",
                            Toast.LENGTH_LONG).show();
                    //e.printStackTrace();
                }

            }
        });

    }

    private LocationListener MyLocationListener() {
        // TODO Auto-generated method stub
        return null;
    }
}
4

1 に答える 1

0

変数latlognはクラスのメンバーですが、MyLocationListenerそのように使用することはできません。また、タイプミスだと思われるものを使用lagn していることにも注意してください:)OnClickListener()

于 2012-04-24T07:27:06.097 に答える