与搜索栏的Andr​​oid通知 [英] android notification with seekbar

查看:160
本文介绍了与搜索栏的Andr​​oid通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要填充我的用图像和搜索栏通知.....
我通知功能如下...

want to populate My notification with images and a seekbar..... My notification function is as follows...

public void showNotification(){

    // define sound URI, the sound to be played when there's a notification
            //Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, "Custom Notification", when);

    NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(this, NotificationReceiver.class);
    PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, notificationIntent, 0);
   // notification.contentIntent = contentIntent;


    Intent notificationIntent2 = new Intent(this, NotificationReceiver2.class);
    PendingIntent pIntent2 = PendingIntent.getActivity(MainActivity.this, 0, notificationIntent2, 0);
   // notification.contentIntent = contentIntent2;

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.result);
    contentView.setImageViewResource(R.id.image, R.drawable.ninja);
    contentView.setImageViewResource(R.id.image2, R.drawable.ninja);

    contentView.setOnClickPendingIntent(R.id.image, pIntent);
    contentView.setOnClickPendingIntent(R.id.image, pIntent2);
   // contentView.setTextViewText(R.id.title, "Custom notification");
  //  contentView.setTextViewText(R.id.text, "This is a custom layout");
    notification.contentView = contentView;



    notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
    notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
    notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
    notification.defaults |= Notification.DEFAULT_SOUND; // Sound

    mNotificationManager.notify(0, notification);
}

和我想通知膨胀的布局如下:

and the layout which i want to inflate in notification is as follows

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    </LinearLayout>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    </LinearLayout>
    </LinearLayout>

但是,当我想说明的异常通知

But when I want to show notification with the exception

01-08 12:33:25.393: E/AndroidRuntime(24069): FATAL EXCEPTION: main
01-08 12:33:25.393: E/AndroidRuntime(24069): android.app.RemoteServiceException: Bad     notification posted from package com.example.androidnotificationbar: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.example.androidnotificationbar id=0 tag=null score=0 notn=Notification(pri=0 contentView=com.example.androidnotificationbar/0x7f030001 vibrate=default sound=default defaults=0x7 flags=0x20 kind=[null]) tickerText=Custom Notification contactCharSeq=null when=1420700605072 threadId=0)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1407)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at android.os.Looper.loop(Looper.java:174)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at android.app.ActivityThread.main(ActivityThread.java:4952)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at java.lang.reflect.Method.invokeNative(Native Method)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at java.lang.reflect.Method.invoke(Method.java:511)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
01-08 12:33:25.393: E/AndroidRuntime(24069):    at dalvik.system.NativeStart.main(Native Method)

请给我一些建议与此

推荐答案

据我所知RemoteViews不支持搜索栏,你不能实施自己的远程视图。而在通知搜索栏不是一个好主意,因为默认通知手势在所有。你可以使用 https://github.com/pingpongboss/StandOut 任何方式来实现像水木清华浮动通知您的需要。

As far as I know RemoteViews does not support SeekBar and you cannot implement your own remote view. And seekbar in notification not a good idea at all because of default notification gestures. Any way you could use https://github.com/pingpongboss/StandOut to implement smth like floating notification for your need.

这篇关于与搜索栏的Andr​​oid通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆