Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: I apologize, I misunderstood the use of a BroadcastReceiver. If I understand correctly, when a Broadcast Intent is intercepted by your BroadcastReceiver, it calls the <code>onReceive</code> method. Here is the function header:</p> <pre><code>public abstract void onReceive (Context context, Intent intent) </code></pre> <p>Notice that a context is passed as an argument to this function. This context is the Context in which the receiver is running. Go ahead and try using that with the methods I specified below. Here's my reference: <a href="http://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive%28android.content.Context,%20android.content.Intent%29" rel="nofollow noreferrer">http://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive%28android.content.Context,%20android.content.Intent%29</a></p> <p>Hope this helps!</p> <p>ORIGINAL POST: One possible way to do this is to pass the application context as a constructor argument for your SMS Receiver Class:</p> <pre><code>public SMSReceiver(Context context, ...[other args]){ this.context = context; //Rest of constructor code } </code></pre> <p>And then when you instantiate your SMS Receiver in your activity:</p> <pre><code>SMSReceiver receiver = new SMSReceiver(this, ...[other args]); </code></pre> <p>With this context, you are able to get the Shared Preferences.</p> <pre><code>Preferences preferences = context.getSharedPreferences("NAME", [int Mode]); </code></pre> <p>The user Pentium10 provided a very thorough answer regarding preference access in this link: <a href="https://stackoverflow.com/questions/2614719/how-do-i-get-the-sharedpreferences-from-a-preferenceactivity-in-android">How do I get the SharedPreferences from a PreferenceActivity in Android?</a> </p> <p>Here is the tidbit of code you'll be interested in (with a minor edit to match what I have above):</p> <pre><code>import android.preference.PreferenceManager; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // then you use prefs.getBoolean("keystring", true); //or whatever method you need to retrieve your data </code></pre>
 

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