无法在Android Studio中发送消息

问题描述

我正在开发女性安全应用程序。我想在用户摇动手机时使用SmsManager通过消息发送用户位置。我的国家/地区有两家手机运营商,

Orredo

Telenor

发送消息。当我使用

Orredo,我可以发送消息,但是当我使用 Telenor,我无法发送消息。我想知道是什么原因造成的。由于我的密码或我的手机运营商?

这是我的代码。 我的代码可能有点混乱,没有任何意义,因为我是新手,并且是从头开始开发此应用的。

 @Override
    protected void onResume() {
        super.onResume();

        if (broadcastReceiver == null) {
            broadcastReceiver = new broadcastReceiver() {
                @Override
                public void onReceive(Context context,Intent intent) {

                        tv1.append(""+intent.getExtras().get("Coordinate"));
                        Intent intent1 = new Intent(getApplicationContext(),GPS_Service.class);
                        stopService(intent1);
                        Log.d(TAG,"onReceive: "+tv1.getText());



                }
            };
        }
        registerReceiver(broadcastReceiver,new IntentFilter("location_update"));
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (broadcastReceiver != null) {
            unregisterReceiver(broadcastReceiver);
        }
    }


    private void enable_buttons() {
        mRegister.setonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,Register.class);
                startActivity(intent);
            }
        });


    }

    private final SensorEventListener sensorListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent sensorEvent) {
            float x = sensorEvent.values[0];
            float y = sensorEvent.values[1];
            float z = sensorEvent.values[2];

            acelLast = acelVal;
            acelVal = (float) Math.sqrt((double) (x * x + y * y + z * z));
            float delta = acelVal - acelLast;
            shake = shake * 0.9f + delta;


            if (shake > 12) {
                mDatbaseHelper =new DatabaseHelper(MainActivity.this);
                Cursor data = mDatbaseHelper.getData();
                while (data.movetoNext()) {
                    phone1 = data.getString(1);
                    phone2 = data.getString(2);
                }

                @SuppressLint("MissingPermission")

                String s = "tel:" + phone1;
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse(s));
                if (ActivityCompat.checkSelfPermission(MainActivity.this,Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                startActivity(intent);
                ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.SEND_SMS},SEND_SMS_PERMISSION_CODE);




                if (checkPermission(Manifest.permission.SEND_SMS)) {
                    SmsManager smsManager = SmsManager.getDefault();
                   smsManager.sendTextMessage(phone1,null,"google.com/maps/place/"+tv1.getText().toString(),null);
                   Log.d(TAG,"onSensorChange: "+tv1.getText().toString());
                    Toast.makeText(MainActivity.this,"Message Sent!",Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this,"Permission Denied",Toast.LENGTH_SHORT).show();
                }

            }
        }

这是我的GPS服务代码

public class GPS_Service extends Service {
    private LocationListener listener;
    private LocationManager locationManager;
    public static final String TAG ="GPS_Service";


    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @SuppressLint("MissingPermission")
    @Override
    public void onCreate() {
        super.onCreate();
        listener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                Intent i = new Intent("location_update");
                i.putExtra("Coordinate",location.getLatitude() + "," + location.getLongitude());
//                i.putExtra("Latitude",location.getLatitude());
//                i.putExtra("Longitude",location.getLongitude());
                sendbroadcast(i);

            }

            @Override
            public void onStatusChanged(String provider,int status,Bundle extras) {

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderdisabled(String provider) {
                Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);
            }


        };
        locationManager =(LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000,listener);
    }
    @Override
    public void onDestroy() {
        if(locationManager!=null)
        {
            locationManager.removeUpdates(listener);
        }
        super.onDestroy();
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)