Can i use below way to start an broadcast receiver? Some one can get it run but i can’t. I don’t know why.
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName componentName = new ComponentName("brd2.demo", "brd2.demo.BroadcastReceiver");
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
this is my Android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="brd2.demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name="brd2.demo.BroadcastReceiverDemo2Activity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="brd2.demo.CallBroadcastReceiver">
<intent-filter >
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
Pls, help me.
If you are taking care to add appropriate actions in receivers.
And if your receiver class is
extending broadcast receiver,Then system will take care to call your broadcast receiver.
You dont need to start broadcast receiver manually (Until and unless you are creating custom broadcasts).
In your case if
CallBroadcastReceiveris extendingBroadcastReceiverand if you have written appropriate logic inonReceivemethod,Then this class will automatically get called when you make new call or if phone rings.Hope this help.