- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
今天我试了又试,只是为了获得带有 2 个按钮和一个 TextView 的自定义消息。我已经得到 XML 了。但是我尝试使用的代码只是给我 Force Close
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.main);
contentView.setImageViewResource(R.id.Button01, R.drawable.icon);
contentView.setTextViewText(R.id.Button01, "Hello, this message is in a custom expanded view");
Intent notificationIntent = new Intent(this, main.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
我很迷茫所以请不要把我送到http://developer.android.com/guide/topics/ui/notifiers/notifications.html我试过了。
如果有人能从一开始就告诉我,我会非常高兴,因为我一整天都在尝试这个,真的很感激一个好的答案!
谢谢!
//卢卡斯
编辑* VIKTOR 的完整代码
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews;
public class main extends Activity {
/** Called when the activity is first created. */
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.main);
contentView.setImageViewResource(R.id.Button01, R.drawable.icon);
contentView.setTextViewText(R.id.Button01, "Hello, this message is in a custom expanded view");
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, main.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
final int CUSTOM_VIEW_ID = 1;
mNotificationManager.notify(CUSTOM_VIEW_ID, notification);
}
}
堆栈跟踪:
04-27 14:43:07.035: ERROR/StatusBarService(337): couldn't inflate view for notification Com.haxxzor.multitask/0x1
04-27 14:43:07.035: ERROR/StatusBarService(337): android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.HorizontalScrollView
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
04-27 14:43:07.035: ERROR/StatusBarService(337): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.widget.RemoteViews.apply(RemoteViews.java:939)
04-27 14:43:07.035: ERROR/StatusBarService(337): at com.android.systemui.statusbar.StatusBarService.makeNotificationView(StatusBarService.java:524)
04-27 14:43:07.035: ERROR/StatusBarService(337): at com.android.systemui.statusbar.StatusBarService.addNotificationViews(StatusBarService.java:553)
04-27 14:43:07.035: ERROR/StatusBarService(337): at com.android.systemui.statusbar.StatusBarService.addNotification(StatusBarService.java:382)
04-27 14:43:07.035: ERROR/StatusBarService(337): at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:178)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.os.Looper.loop(Looper.java:123)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-27 14:43:07.035: ERROR/StatusBarService(337): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 14:43:07.035: ERROR/StatusBarService(337): at java.lang.reflect.Method.invoke(Method.java:507)
04-27 14:43:07.035: ERROR/StatusBarService(337): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-27 14:43:07.035: ERROR/StatusBarService(337): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-27 14:43:07.035: ERROR/StatusBarService(337): at dalvik.system.NativeStart.main(Native Method)
04-27 14:43:07.035: ERROR/StatusBarService(337): Caused by: android.view.InflateException: Binary XML file line #1: Class not allowed to be inflated android.widget.HorizontalScrollView
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:530)
04-27 14:43:07.035: ERROR/StatusBarService(337): at android.view.LayoutInflater.createView(LayoutInflater.java:477)
04-27 14:43:07.035: ERROR/StatusBarService(337): ... 17 more
04-27 14:43:10.113: ERROR/AndroidRuntime(815): FATAL EXCEPTION: main
04-27 14:43:10.113: ERROR/AndroidRuntime(815): android.app.RemoteServiceException: Bad notification posted from package Com.haxxzor.multitask: Couldn't expand RemoteViews for: StatusBarNotification(package=Com.haxxzor.multitask id=1 tag=null notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x2))
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1044)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at android.os.Looper.loop(Looper.java:123)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at java.lang.reflect.Method.invoke(Method.java:507)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-27 14:43:10.113: ERROR/AndroidRuntime(815): at dalvik.system.NativeStart.main(Native Method)
04-27 14:47:12.065: ERROR/InputDispatcher(44): channel '40643090 com.notif/com.notif.main (server)' ~ Consumer closed input channel or an error occurred. events=0x8
04-27 14:47:12.065: ERROR/InputDispatcher(44): channel '40643090 com.notif/com.notif.main (server)' ~ Channel is unrecoverably broken and will be disposed!
04-27 14:47:31.551: ERROR/AndroidRuntime(885): FATAL EXCEPTION: main
04-27 14:47:31.551: ERROR/AndroidRuntime(885): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.notif/com.notif.main}: java.lang.IllegalMonitorStateException: object not locked by thread before notify()
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.os.Looper.loop(Looper.java:123)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at java.lang.reflect.Method.invoke(Method.java:507)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at dalvik.system.NativeStart.main(Native Method)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): Caused by: java.lang.IllegalMonitorStateException: object not locked by thread before notify()
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at java.lang.Object.notify(Native Method)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at com.notif.main.onCreate(main.java:27)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-27 14:47:31.551: ERROR/AndroidRuntime(885): ... 11 more
最佳答案
由于您发布了错误消息,此行会告诉您自定义通知未成功的原因:
Caused by: android.view.InflateException: Binary XML file line #1: Class not allowed to be inflated android.widget.HorizontalScrollView
移除 HorizontalScrollView
并使用简单的 TextView
s/ImageView
s 进行测试。
关于安卓开发 : How to make a custom status bar Notification?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5805579/
我并不总是编写 make 文件,但当我这样做时,我喜欢尝试并写好它们。试图使界面与其他开发人员的期望一致始终是一项艰巨的任务。我正在寻找的是所有常见的 make some clean (GNU) ma
例如,我在运行 makefile 时收到这样的错误: make[3]: *** [/home/ziga/Downloads/openwrt/rakun_openwrt/staging_dir/ho
我必须创建一个 Makefile,它从不同文件夹中的 .c 文件创建单个可执行文件。 .c 文件包含来自任何这些文件夹的头文件。根目录有3个子目录x/y、x/z、a,所有这些子目录都有一些.c和.h文
您好,我有一个简单的 MakeFile,其中包含: clean: rm -f ex1 但是当我运行命令make clean 时,出现以下错误: make: *** No rule to mak
我已经为一些软件安装了它,但现在我根本不使用那个软件,所以我需要移除MinGW才能使用Cygwin进行Android开发。。我使用的是64位Windows 7
以下是针对我遇到的问题的简化生成文件: all: /tmp/makey/../filey @echo All done /tmp/filey: @echo Filey 当我运行 mak
获取错误: make: *** No rule to make target all. Stop." 在安装nagios主机期间运行此命令make all 最佳答案 可能的常见错误: 确保将文件命名为
当使用 -jN 运行 gnu-make 规则时,make 会创建 jobserver用于管理跨子制造商的工作数量。此外,您可以通过在 make 配方前添加 + 前缀来“将作业服务器环境传递”到 mak
使用 GNU Make 4.1 概括 我调用一个子品牌 b.mk来自生成文件 a.mk .b.mk被调用以确保构建子系统。 有时我想强制一个目标为 a.mk重制: make -f a.mk --al
这个问题与问题 2543127 的精神相似。 . 我有一个带有头文件列表的 gnu makefile。每个头文件可能位于不同的目录中,例如, HEADERS = $(wildcard *.h) $(w
假设我有以下 GNU make 目标: create_dir: @mkdir objects build_asm: $(ASM_FILES) @echo
我有一个具有以下结构的 Makefile(工作示例)。 .PHONY: image flashcard put-files put-files: @echo "=== put-files" i
我想要一个这样的makefile: cudaLib : # Create shared library with nvcc ocelotLib : # Create shared li
有没有比更好的方法来获取 GNU make 变量的第一个字符 FIRST=$(shell echo $(VARIABLE) | head -c 1) (不仅笨重而且还要调用外部shell)? 最佳答案
我通常使用像 cmake 这样的高级构建系统来构建我的 C/C++ 代码。但是由于各种原因,我直接使用 GNU make。 我正在进行递归构建,其中每个目录都有一个 makefile。 我最近不得不将
我通常使用像 cmake 这样的高级构建系统来构建我的 C/C++ 代码。但是由于各种原因,我直接使用 GNU make。 我正在进行递归构建,其中每个目录都有一个 makefile。 我最近不得不将
我安装了最新的mingw,发现没有mingw32-make了。有make.exe,所以我想知道最近是否将mingw32-make重命名为make.exe。 最佳答案 我不知道您从哪里获得 MinGW,
我正在使用 CentOS,但由于一个错误,许多软件包被删除了。所以我没有 yum 和 rpm。所以我想从源代码手动制作 yum,但我也没有制作。我知道一切都会用“制作包”制作。但是 make 自己呢?
考虑这个Makefile: .PHONY: all all: main.txt main.txt: build/main.txt cp build/main.txt . %/main.txt:
假设目录输入中有 1000 个扩展名为 .xhtml 的文件,并且这些文件的某个子集(输出路径在 $(FILES) 中)需要通过 xslt 转换为目录输出中具有相同名称的文件.一个简单的 make 规
我是一名优秀的程序员,十分优秀!