Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i call an activity after a sms has been received by application?
    primarykey
    data
    text
    <p>I am using BroadcastReceiver class for receiving the sms. My main class code is:</p> <pre><code>package org.apache.sms; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; public class SMSApp 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 = ""; 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]); str += "SMS from " + msgs[i].getOriginatingAddress(); str += " :"; str += msgs[i].getMessageBody().toString(); str += "\n"; } //---display the new SMS message--- Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); /* Intent i = new Intent(context,Second.class); i.putExtra("msg",str); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); */ } this.abortBroadcast(); } </code></pre> <p>}</p> <p>manifest file is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.apache.sms" android:versionCode="1" android:versionName="1.0.0"&gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;receiver android:name=".SMSApp"&gt; &lt;intent-filter android:priority="100"&gt; &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt; &lt;/uses-permission&gt; &lt;/manifest&gt; </code></pre> <p>Right now my application displays the message in a pop up. </p> <p>But i want to display the second screen when my application receive the sms. For this i have added following code after Toast.makeText method :</p> <pre><code> Intent i = new Intent(context,Second.class); i.putExtra("msg",str); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); </code></pre> <p>After adding following code nothing is happening. No error only message comes in notification bar.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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