INNER CODE UNIT · Java

onReceive

hussien89aa/AndroidTutorialForBeginners · BroadcastReceiver.java:8

    public void onReceive(Context context, Intent intent) {
        // get the bundles in the message
        final Bundle bundle = intent.getExtras();
        // check the action equal to the action we fire in broadcast,
        if   (   intent.getAction().equalsIgnoreCase("com.example.Broadcast"))
            //read the data from the intent
            Toast.makeText(context,bundle.getString("username"),Toast.LENGTH_LONG).show();

  if   (   intent.getAction().equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED"))
{
	  if (bundle != null) {

                final Object[] pdusObj = (Object[]) bundle.get("pdus");
                SmsMessage[] messages = new SmsMessage[pdusObj.length];
                for (int i = 0; i < messages.length; i++) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        String format = bundle.getString("format");
                        messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i], format);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…