Skip to main content

Posts

Showing posts with the label broadcastreceiver

Simple BroadcastReceiver won"t work

I try to develope a simple Broadcastreceiver. Here's my code: public class MyClass extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Bundle extras = intent.getExtras(); if (extras != null) { String state = extras.getString(TelephonyManager.EXTRA_STATE); Log.w("DEBUG", state); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { String phoneNumber = extras .getString(TelephonyManager.EXTRA_INCOMING_NUMBER); Toast.makeText(context, phoneNumber, Toast.LENGTH_LONG).show(); Log.w("DEBUG", phoneNumber); } } } } Manifest.xml: <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > &l

Android BroadCastReceiver refresh all activities

I have an issue using BroadCastreceiver to refresh activities in my application. I'm using a service which is doing some calculations and in onDestroy() method I'm doing this : @Override public void onDestroy(){ super.onDestroy(); Intent intent = new Intent("finish"); this.sendBroadcast(intent); } and in my activities I'm doing this : receiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { if(intent.getAction().equals("finish")) { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); TabGroupActivity parentActivity = (TabGroupActivity)getParent(); Intent previewMessage = new Intent(Tutorial.this, Tutorial.class); parentActivity.startChildActivity("Tutorial", previewMessage); progressBar.setVisibility(View.GONE); sync.setImageResource(R.drawable.syn

Android - Get preference from activity to broadcast receiver

I'm developing an Android app but I have a problem. When I try to get a saved preference from my Activity and use it in a BroadcastReceiver , it tells me that string I'm looking for doesn't exist. This is how I save the preference in the Activity: private void SavePreferences(String key, String value) { SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.commit(); } And this is how I try to get the preference in BroadcastReceiver : String pref = PreferenceManager.getDefaultSharedPreferences(context) .getString("MEM1", "Does not exist"); Where MEM1 is the string I saved before. My problem is that when I read pref , I'm getting the default value of Does not exist , instead of my preference value ( MEM1 ). Can someone point me to where I'm going wrong?

ON & OFF Android Broadcastreceiver

Im creating an app in which i do a task when i receive a call (detect RINGING state with a BROADCASTRECEIVER ).My question is that,can I register and unregister (literally;ON and OFF) his broadcastreceiver from an activity having 2 buttons;say one for ON and another for OFF? Does it require the BROADCASTRECEIVER to be declared inside the activity?If I do so,can i register and unregister it,via the activity?

BroadcastReceiver not working on Android 3.0

I have a plugin framework which uses broadcast intents for communication between main application and plugins. On start main app sends a broadcast intent sendBroadcast(new Intent("com.mypackage.myapp.custom.intent.action.ADDON_REQ")); Each plugin app has a broadcast receiver registered in its manifest file. <receiver android:name="IncomingReceiver" android:enabled="true"> <intent-filter> <action android:name="com.mypackage.myapp.custom.intent.action.ADDON_REQ" > </action> </intent-filter> </receiver> Plugin application does not have any activities defined. This framework works fine on all Android versions lower that 3.0. Starting from Honeycomb the broadcast receiver in plugin is never called. I could not fix this until I added a main activity in the plugin app. With the activity defined in manifest existing broadcast receiver started to receive