Note that there are some explanatory texts on larger screens.

plurals
  1. POCall function in service from broadcastReceiver
    primarykey
    data
    text
    <p>I have been struggling with the problem. I have a Broadcast receiver that is suppose to receive SMS' and it does that, but I want to use a method/function in my Service, the intent is to make it a foreground service eventually, that never shuts down. The Broadcastreceiver looks like this:</p> <pre><code>import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; 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; 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]); } //want to send msgs[] to SmsService } } } </code></pre> <p>In the manifest for making it receive I have added:</p> <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt; &lt;uses-permission android:name="android.permission.BROADCAST_SMS"/&gt; &lt;uses-permission android:name="android.permission.READ_SMS"/&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS"/&gt; &lt;uses-permission android:name="android.permission.SEND_SMS" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".MainActivity" android:label="@string/title_activity_main" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name=".SmsReceiver" &gt; &lt;intent-filter&gt; &lt;action android:name= "android.provider.Telephony.SMS_RECEIVED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;service android:name="SmsService"&gt;&lt;/service&gt; &lt;/application&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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