how to show notification that shows up on main screen and all applications - Android -


i wanna show notification messaging app line, both on main screen , on application shows notification box message in seconds , disappear then.

something this:

example

so possible ways ? custom toast? or custom dialog?

you have create window animation :

myservice.java

import android.app.service; import android.content.context; import android.content.intent; import android.graphics.pixelformat; import android.os.ibinder; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.view.windowmanager;  /**  * created darshan.mistry on 7/18/2015.  */ public class myservice extends service {      view mview;      @override     public ibinder onbind(intent intent) {         return null;     }      @override     public void oncreate() {         super.oncreate();          // instance of windowmanager         windowmanager mwindowmanager = (windowmanager) getsystemservice(window_service);          layoutinflater minflater = (layoutinflater)                 getsystemservice(context.layout_inflater_service);          // inflate required layout file         mview = minflater.inflate(r.layout.abc, null);          // attach onclicklistener         mview.findviewbyid(r.id.someview).setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // can fire intent accordingly - deal click event                 // stop service - removes `mview` window                 // because ondestroy() called - that's remove `mview`                 stopself();             }         });          // layoutparams `mview`         // main attraction here `type_system_error`         // noted above, `type_system_alert` not work on lockscreen         // `type_system_overlay` works focusable - no click events         // `type_system_error` supports these requirements         windowmanager.layoutparams mlayoutparams = new windowmanager.layoutparams(                 viewgroup.layoutparams.wrap_content,                 viewgroup.layoutparams.wrap_content, 0, 0,                 windowmanager.layoutparams.type_system_error,                 windowmanager.layoutparams.flag_show_when_locked                         | windowmanager.layoutparams.flag_dismiss_keyguard                         | windowmanager.layoutparams.flag_turn_screen_on                         | windowmanager.layoutparams.flag_keep_screen_on,                 pixelformat.rgba_8888);          // finally, add view window         mwindowmanager.addview(mview, mlayoutparams);     }      @override     public void ondestroy() {         super.ondestroy();          // remove `mview` window         removenow();     }        // removes `mview` window     public void removenow() {         if (mview != null) {             windowmanager wm = (windowmanager) getsystemservice(window_service);             wm.removeview(mview);         }     } } 

myreceiver.java

import android.content.broadcastreceiver; import android.content.context; import android.content.intent;  /**  * created darshan.mistry on 7/18/2015.  */ public class myreciver extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {         intent intent1 = new intent(context, myservice.class);         context.startservice(intent1);     } } 

in manifest file, add permission:

<!-- [my service , reciver] -->         <service             android:name=".myservice"             android:exported="true" />         <receiver android:name=".myreciver">             <intent-filter>                 <action android:name="com.tutorialspoint.custom_intent"></action>             </intent-filter>         </receiver> 

myservice class xml file :

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="fill_parent"     android:layout_height="100dp"     android:background="@android:color/white">      <textview         android:id="@+id/someview"         android:layout_width="fill_parent"         android:layout_height="100dp"         android:layout_gravity="center"         android:background="@android:color/white"         android:gravity="center"         android:text="this demo"         android:textcolor="@android:color/black" />  </relativelayout> 

you have call myservice have got notification add below lines:

 intent intent = new intent();         intent.setaction("com.tutorialspoint.custom_intent");         sendbroadcast(intent); 

this simple example have got ideas how implement notification line app.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -