Note that there are some explanatory texts on larger screens.

plurals
  1. POShow dialog after sms receive
    text
    copied!<p>I want to receive sms and show Dialog. How can i do that?</p> <p>SmsReceiver:</p> <pre><code>public class SMSReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; String num = ""; if (bundle != null) { //---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i&lt;msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); if (i==0) { //---get the sender address/phone number--- num += msgs[i].getOriginatingAddress(); } //---get the message body--- str += msgs[i].getMessageBody().toString(); } //---display the new SMS message--- if (num.equals("+XXXXXXXXX")){ Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); //What to do here? } //---prevent this SMS message from being broadcasted--- abortBroadcast(); Log.d("SMSReceiver", str); } } } </code></pre> <p>My Main:</p> <pre><code>public class MainActivity extends FragmentActivity implements YesNoDialogListener { GoogleMap googleMap; Marker marker = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Getting Google Play availability status int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); // Showing status if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available int requestCode = 10; Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); dialog.show(); } else { // Google Play Services are available // Getting reference to the SupportMapFragment of activity_main.xml SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // Getting GoogleMap object from the fragment googleMap = fm.getMap(); // get my actual position and display a blue dot googleMap.setMyLocationEnabled(true); Location myLocation = googleMap.getMyLocation(); if( myLocation != null ){ Toast.makeText(this, "Latitude: " + myLocation.getLatitude() + "\nLongitude: " + myLocation.getLongitude(), Toast.LENGTH_SHORT).show(); } if( myLocation == null ){ Toast.makeText(this, "Chujnia", Toast.LENGTH_SHORT).show(); } } } //==Dialog yes/no public void btnShowYesNoDialog(View view) { showYesNoDialog(); } public void showYesNoDialog() { FragmentManager fragmentManager = getSupportFragmentManager(); YesNoDialogFragment yesnoDialog = new YesNoDialogFragment(); yesnoDialog.setCancelable(false); yesnoDialog.setDialogTitle("New accident"); yesnoDialog.show(fragmentManager, "yes/no dialog"); } @Override public void onFinishYesNoDialog(boolean state) { Toast.makeText(this, "Returned from dialog: " + state, Toast.LENGTH_SHORT).show(); SmsManager sms = SmsManager.getDefault(); if (state == true){ sms.sendTextMessage("+XXXXXX", null, "OK", null, null); } else{ sms.sendTextMessage("+XXXXXXX", null, "No", null, null); } } } </code></pre> <p>How to execute btnShowYesNoDialog from SmsReceive? Now it works only when I press the button which is connected to btnShowYesNoDialog?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload