java - android broadcast receiver and service to get notification -


hi have used following code in receiver class

public class alarmreceiver extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {         log.e("the time right","yay!");         intent = new intent(context, alarmservie.class);         context.startservice(i);     }  } 

here code used in service class

public class alarmservie extends service {     @nullable     @override     public ibinder onbind(intent intent) {         return null;     }      @override     public void onstart(intent intent, int startid) {         super.onstart(intent, startid);         log.e("onstart:","came" );      /*  notificationmanager notifyman = (notificationmanager) getsystemservice(notification_service);         intent main_activity = new intent(this.getapplicationcontext(), mainactivity.class);         pendingintent o = pendingintent.getactivity(this, 0, main_activity, 0);          /*notification noti = new notification.builder(this)                 .setcontenttitle("reminder pill")                 .setcontenttext("click info")                 .setautocancel(true)                 .setcontentintent(o)                 .build();*/         notificationmanager nm = (notificationmanager) this.getapplicationcontext().getsystemservice(notification_service);         intent in = new intent(this.getapplicationcontext(), mainactivity.class);         pendingintent pending = pendingintent.getactivity(this, 0, in, 0);         notificationcompat.builder mbuilder =new notificationcompat.builder(alarmservie.this);         mbuilder.setcontenttitle("pill reminder");         mbuilder.setcontenttext("click here view");         //mbuilder.setsound(sound);          taskstackbuilder ts=taskstackbuilder.create(this);         ts.addparentstack(mainactivity.class);         nm.notify(9999,mbuilder.build());      }} 

i created code notification.when run app receiver class triggered not moving service class invoke notification.can whats wrong in code or me how notification using broadcast receiver , service in detailed tutorial

here manifest file , me put code exactly

<uses-permission android:name="android.permission.vibrate"/>     <uses-permission android:name="android.permission.wake_lock"/>     <uses-permission android:name="com.android.alarm.permission.set_alarm"/>       <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme">         <activity             android:name=".mainactivity"             android:label="@string/app_name"             android:theme="@style/apptheme.noactionbar">             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />                </intent-filter>         </activity>         <receiver android:name=".alarmreceiver"></receiver>         <activity android:name=".set"></activity><!-- attention: auto-generated add google play services project      app indexing.  see https://g.co/appindexing/androidstudio more information. -->         <meta-data             android:name="com.google.android.gms.version"             android:value="@integer/google_play_services_version" />     </application>  </manifest> 

please explain in detail problem in code.please tell put service tag

you must declare service in manifest also. intent start service sent system system tries find right application component handle particular intent using information passed in manifest files.

it should enough, i'm not sure if put service in default package.

<application>     ....     <service android:name=".alarmservie"/>     .... </application> 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -