I try to get a broadcast receiver working. Should be as simple as possible, I have my manifest like this:
&l
Try specifying what actions your receiver should catch in the manifest. You can do this as such:
<receiver android:name="com.mytest.intentRec.MyIntentRec">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
it is insufficient to make just new Intent();
. You have to specify it with some action. Also, you have to specify in your manifest the intent filter for this particular action. Please read more here and here.
Please setClass
for your Intent,
EX:
public class mainAct extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i=new Intent("any string");
i.setClass(this, MyIntentRec.class);
this.sendBroadcast(i);
}
}
That is what it means " The absence of any filters means that it can be invoked only by Intent objects that specify its exact class name."
[Old answer]
You should register what kind of actions you need in the manifest.
Ex:
<receiver android:name="com.mytest.intentRec.MyIntentRec" android:enabled="true" >
<intent-filter>
<action android:name="your.intent" />
</intent-filter>
</receiver>
send it,
this.sendBroadcast(new Intent("your.intent"));
You didn't define any Intent Filters in the manifest for your BroadcastReceiver. Specify one for a custom Action type. You also have to define this custom Action type in the Intent you brodcast upon startup.