Не могу отправить сообщение в Android StudioAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Не могу отправить сообщение в Android Studio

Сообщение Anonymous »

Я разрабатываю приложение для безопасности женщины. Я хочу отправить пользовательское местоположение через сообщение, используя Smsmanager, когда пользователь встряхивает телефон. У меня есть два оператора мобильного телефона в моей стране, < /p>

orredo < /p>
< /blockquote>
и < /p>

telenor < /p>
< /blockquote>
whr. />
Орредо, я могу отправлять сообщение, но когда я использую
telenor, я не могу отправить сообщение. Я хочу знать, что причина. царапина. < /p>
@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, 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();
}

}
}
< /code>
И вот мой код для службы GPS. < /p>
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,0,listener);
}
@Override
public void onDestroy() {
if(locationManager!=null)
{
locationManager.removeUpdates(listener);
}
super.onDestroy();
}
}


Подробнее здесь: https://stackoverflow.com/questions/635 ... oid-studio
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»