开发者

Android BroadcstReciever

I am creating an application in which I am using a broadcast receiver. I am new to android, so I am not sure how to add the receiver in the manifest file. My code:

<receiver android:name="Reciever" />

Reciever is开发者_开发问答 the name of a class which extends BroadcastReceiver. When the user clicks on button then after 5 seconds I want to call this Receiver. So I have written this:

AlarmManager am= (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, cal.getTimeInMillis(), sender);

Here "sender" is pending intent. But it's not working, please suggest to me?


The android:name should point to the receiver class e.g 'com.foo.TestReceiver' or just '.TestReceiver' because you might have stated the package name earlier. Also, just having a receiver doesn't make much sense. You need an tag inside the receiver to specify the trigger when your receiver runs. Take a look at the code samples provided at the developer site for more.


U missed a . in Front of the Receiver name.

It should be

<receiver android:name=".Reciever"></receiver>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜