android - Broad Cast Manager issue -
i new in android programming.i create 1 alarm manager , broadcast manager program . broadcast manager class defined inner class in main activity. inner class not working. give code here. please me.
public class alarmactivity extends activity { button btn1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); btn1=(button) findviewbyid(r.id.button1); btn1.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub startalert(null); } }); } public void startalert(view view) { alarmmanager am=(alarmmanager)this.getsystemservice(this.alarm_service); intent = new intent(this, broadcas.class); pendingintent pi = pendingintent.getbroadcast(this, 0,i,0); am.setrepeating(alarmmanager.rtc_wakeup, system.currenttimemillis(), 1000 * 15, pi); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } public class broadcas extends broadcastreceiver { @override public void onreceive(context context, intent intent) { // todo auto-generated method stub system.out.println("**********************hello***********************************"); } } }
have registered receiver proper name in manifest file? giving broadcastreceiver name won't work in case , need use name
alarmactivity$broadcas
edit: activity class:
public class maintestactivity extends activity { private button send_broadcast = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main_test); send_broadcast = (button) findviewbyid(r.id.send_broadcast); send_broadcast.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub startalert(null); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main_test, menu); return true; } public void startalert(view view) { alarmmanager = (alarmmanager) getsystemservice(context.alarm_service); intent = new intent(this, broadcas.class); pendingintent pi = pendingintent.getbroadcast(this, 0, i, 0); am.setrepeating(alarmmanager.rtc_wakeup, system.currenttimemillis(), 1000 * 15, pi); } public static class broadcas extends broadcastreceiver { @override public void onreceive(context context, intent intent) { // todo auto-generated method stub system.out.println("**********************hello***********************************"); } } }
and manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.coding.test" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.coding.test.maintestactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <receiver android:name="maintestactivity$broadcas"></receiver> </application> </manifest>
Comments
Post a Comment