Android custom notification Bar encountered problems

Source: Internet
Author: User

When customizing the layout of the notification bar, to copy a layout.xml file, reference, but always error

ANDROID.APP.REMOTESERVICEEXCEPTION:BAD notification posted from the package com.example.notification:Couldn ' t expand Remoteviews for:statusbarnotification (pkg=com.example.notification id=2 tag=null score=0 notn=Notification (pri=0 contentview=com.example.notification/0x7f030001 vibrate=null sound=null defaults=0x0 flags=0x10 kind=[null]) user= USERHANDLE{0})

Get Notification Manager Notificationmanager Nfmanager = (notificationmanager) getsystemservice (Notification_service); Notification mynotification = new Notification ();//reminder Alert Mynotification.tickertext = "Android: Hello";// Set notification Time Mynotification.when = System.currenttimemillis ();//Set icon Mynotification.icon = r.drawable.ic_launcher;// Set the action of the notification click intent Intent = new Intent (this, mainactivity.class);//A future (advance) action, used to click or clear the notification when the action, pendingintent Pendingintent = Pendingintent.getactivity (this, 0,intent, 0); mynotification.contentintent = pendingintent;// Set remote View remoteviews remoteviews = new Remoteviews (Getpackagename (), r.layout.notification_layout); Mynotification.contentview = Remoteviews;mynotification.flags = Notification.flag_auto_cancel;nfmanager.notify (2, Mynotification);

I've been looking for a long time. The reason is that when you set up a remote layout, the buttons inside the layout file set a static click event

    <button         android:layout_width= "wrap_content"        android:layout_height= "wrap_content"        android:o nclick= "shownotify"        android:text= "notifications"/>

Delete this android:onclick= "shownotify" to run.

Android custom notification Bar encountered problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.