0

这适用于模拟器,但当安装在设备上时,会导致应用程序崩溃。

 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);

我该如何解决这个问题?

日志猫:-

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
4

1 回答 1

1

您的以下代码可在API LEVEL 11 or ABOVE. 这就是它在 API 11 级别以下崩溃的原因。

Insted 你可以使用这种方式.. 你必须添加android-support-v4.jar到你的res/lib文件夹中并且也这样做: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

在此处输入图像描述

API 11 以上:

在此处输入图像描述

于 2013-03-26T05:35:12.897 回答