Android应用程序在执行通知代码时崩溃

Android应用程序在执行通知代码时崩溃

问题描述:

这适用于模拟器,但安装在设备上时会导致应用程序崩溃。Android应用程序在执行通知代码时崩溃

String frndName=getSharedData("myOnlineFriendName"); 
Intent intent = new Intent(this, MainActivity.class); 
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 
Notification noti = new Notification.Builder(this) 
    .setContentTitle("Trace Me! Notification") 
    .setContentText(frndName+"'s New Location:") 
    .setSmallIcon(R.drawable.ic_launcher) 
    .setContentIntent(pIntent) 
    .addAction(R.drawable.ic_launcher, "And more", pIntent).build(); 

NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
playSound("n"); 
noti.flags |= Notification.FLAG_AUTO_CANCEL; 
notificationManager.notify(0, noti); 

我该如何解决这个问题?

logcat的: -

03-26 05:29:33.387: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:33.837: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:34.147: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:34.467: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:34.807: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:35.067: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:35.227: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:35.417: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:35.537: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:35.657: E/WVMExtractor(39): Failed to open libwvm.so 
03-26 05:29:42.127: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property 
03-26 05:29:42.157: E/MapActivity(1016): Couldn't get connection factory client 
03-26 05:29:42.697: E/WVMExtractor(39): Failed to open libwvm.so 
+2

请分享logcat的 – onkar 2013-03-26 04:54:15

+0

告诉我们你的错误.. – 2013-03-26 05:18:34

+0

与Emulator一起工作良好,并且没有错误存在,但是在Real设备上,“Applica重刑已停止工作不幸的是“ – 2013-03-26 05:21:14

你下面的代码是在API LEVEL 11 or ABOVE可用。这就是为什么它在API 11级别以下。

的是insted的,你可以用这样的方式..你必须在你的res/lib文件夹添加android-support-v4.jar也这样做:your Project property ---> Build Path --> add jar.your Project property ---> Build Path --> order & export --> select all。在此之后清除&运行下面的代码。

String frndName = "myOnlineFriendName"; 
     Intent intent = new Intent(this, MainActivity.class); 
     PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 
     Notification noti = new NotificationCompat.Builder(this) 
       .setContentTitle("Trace Me! Notification") 
       .setContentText(frndName + "'s New Location:") 
       .setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent) 
       .addAction(R.drawable.ic_launcher, "And more", pIntent).build(); 

     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     // playSound("n"); 
     noti.flags |= Notification.FLAG_AUTO_CANCEL; 
     notificationManager.notify(0, noti); 

你可以检查你的代码工作在我Android 2.1 Device

enter image description here

以上API 11:

enter image description here

+0

感谢您的快速回复,但是我已经在AP上测试过了我16岁以上..但仍然崩溃! – 2013-03-26 05:41:15

+0

你有试试我的代码?检查我编辑的答案......它的工作正常。确保你已经在你的project/res/lib文件夹中添加了android-support-v4.jar。 – 2013-03-26 05:45:01