Hola quisiera que por favor me ayudaran. Quisiera saber como hago para enviar un SMS al presionar una opción en un menú. este es el código muchas gracias.
package com.servitecnology.servigps;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.hitomi.cmlibrary.CircleMenu;
import com.hitomi.cmlibrary.OnMenuSelectedListener;
import com.hitomi.cmlibrary.OnMenuStatusChangeListener;
public class MainActivity extends AppCompatActivity {
CircleMenu circleMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
circleMenu = (CircleMenu) findViewById(R.id.circle_menu);
circleMenu.setMainMenu(Color.parseColor("#CDCDCD"), R.mipmap.icon_menu, R.mipmap.icon_cancel);
circleMenu.addSubMenu(Color.parseColor("#258CFF"), R.mipmap.icon_home)
.addSubMenu(Color.parseColor("#30A400"), R.mipmap.icon_search)
.addSubMenu(Color.parseColor("#FF4B32"), R.mipmap.icon_notify)
.addSubMenu(Color.parseColor("#8A39FF"), R.mipmap.icon_setting)
.addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.icon_gps)
.addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.icon_gps)
.addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.icon_gps)
.addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.icon_gps)
.addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.icon_gps);
circleMenu.setOnMenuSelectedListener(new OnMenuSelectedListener() {
@Override
public void onMenuSelected(int index) {
switch (index) {
case 0:
Toast.makeText(MainActivity.this, "Motor Encendido", Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(MainActivity.this, "Motor Apagado", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(MainActivity.this, "Sirena Encendida", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(MainActivity.this, "Sirena Apagadada", Toast.LENGTH_SHORT).show();
startActivity(new Intent(MainActivity.this, ThankYouActivity.class));
break;
case 4:
Toast.makeText(MainActivity.this, "Microfono ON", Toast.LENGTH_SHORT).show();
break;
case 5:
Toast.makeText(MainActivity.this, "Microfono OFF", Toast.LENGTH_SHORT).show();
break;
case 6:
Toast.makeText(MainActivity.this, "Buscando Ubicacion", Toast.LENGTH_SHORT).show();
break;
case 7:
Toast.makeText(MainActivity.this, "Rastrerando Ubicacion", Toast.LENGTH_SHORT).show();
break;
case 8:
Toast.makeText(MainActivity.this, "Microfono OFF", Toast.LENGTH_SHORT).show();
break;
}
}
}
);
circleMenu.setOnMenuStatusChangeListener(new OnMenuStatusChangeListener() {
@Override
public void onMenuOpened() {
}
@Override
public void onMenuClosed() {
}
}
);
}
@Override
public void onBackPressed() {
if (circleMenu.isOpened())
circleMenu.closeMenu();
else
finish();
}
}
Los hice de esta forma y no me envia el SMS
CircleMenu circleMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
circleMenu = (CircleMenu) findViewById(R.id.circle_menu);
circleMenu.setMainMenu(Color.parseColor("#CDCDCD"), R.mipmap.icon_menu, R.mipmap.icon_cancel);
circleMenu.addSubMenu(Color.parseColor("#258CFF"), R.mipmap.icon_home)
.addSubMenu(Color.parseColor("#30A400"), R.mipmap.icon_search)
.addSubMenu(Color.parseColor("#FF4B32"), R.mipmap.icon_notify)
.addSubMenu(Color.parseColor("#8A39FF"), R.mipmap.icon_setting)
.addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.icon_gps);
circleMenu.setOnMenuSelectedListener(new OnMenuSelectedListener() {
@Override
public void onMenuSelected(int index) {
switch (index) {
case 0:
Toast.makeText(MainActivity.this, "Motor Encendido", Toast.LENGTH_SHORT).show();
String phone = "3012229034";
String text = "Hi from Stackoverflow.com";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone, null, text , null, null);
break;
case 1:
Toast.makeText(MainActivity.this, "Search button Clicked", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(MainActivity.this, "Notify button Clciked", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(MainActivity.this, "Settings button Clcked", Toast.LENGTH_SHORT).show();
startActivity(new Intent(MainActivity.this, ThankYouActivity.class));
break;
case 4:
Toast.makeText(MainActivity.this, "GPS button Clicked", Toast.LENGTH_SHORT).show();
break;
}
}
}
);
circleMenu.setOnMenuStatusChangeListener(new OnMenuStatusChangeListener() {
@Override
public void onMenuOpened() {
}
@Override
public void onMenuClosed() {
}
}
);
}
@Override
public void onBackPressed() {
if (circleMenu.isOpened())
circleMenu.closeMenu();
else
finish();
}
private void checkSMSStatePermission() {
int permissionCheck = ContextCompat.checkSelfPermission(
this, Manifest.permission.SEND_SMS);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
Log.i("Mensaje", "No se tiene permiso para enviar SMS.");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, 225);
} else {
Log.i("Mensaje", "Se tiene permiso para enviar SMS!");
}
}
}