java.lang.NoSuchMethodError:android.app.Notification $ Builder.addAction [英] java.lang.NoSuchMethodError: android.app.Notification$Builder.addAction

查看:201
本文介绍了java.lang.NoSuchMethodError:android.app.Notification $ Builder.addAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了在那里我已经使用的通知应用程序启动时要显示的Andr​​oid应用程序

I have developed an android application where i have used notification to be displayed when the application starts

应用程序完美的作品,当我运行$ C $的Andr​​oid模拟器在那里,当我尝试运行在具有的4.0.4版本的Andr​​oid真实设备同C

The application works perfect when i run the code on android emulator where as when i try to run the same on real device which has android version of 4.0.4

这引发了我的错误,在logcat中为

It throws me error in the logcat as

05-13 19:06:45.824: E/AndroidRuntime(15402): FATAL EXCEPTION: main
05-13 19:06:45.824: E/AndroidRuntime(15402): java.lang.NoSuchMethodError: android.app.Notification$Builder.addAction
05-13 19:06:45.824: E/AndroidRuntime(15402):    at com.example.gpstracker.MainActivity.onCreate(MainActivity.java:54)
05-13 19:06:45.824: E/AndroidRuntime(15402):    at android.app.Activity.performCreate(Activity.java:4470)
05-13 19:06:45.824: E/AndroidRuntime(15402):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-13 19:06:45.824: E/AndroidRuntime(15402):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-13 19:06:45.824: E/AndroidRuntime(15402):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)

在code,我曾尝试是,

The code which i have tried is ,

Notification noti = new Notification.Builder(this)
                .setContentTitle("Driver GPS Tracker Application")
                .setContentText("9ciphers")
                .setSmallIcon(R.drawable.ic_launcher).setContentIntent(in)
                .addAction(R.drawable.ic_launcher, "Start", i)
                .addAction(R.drawable.ic_launcher, "Stop", in)
                .addAction(R.drawable.ic_launcher, "Exit", pIntent).build();
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        // Hide the notification after its selected
        noti.flags |= Notification.FLAG_AUTO_CANCEL;

        notificationManager.notify(0, noti);
        Toast.makeText(getApplicationContext(), "Application Started", Toast.LENGTH_SHORT).show();
        notifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

任何人都可以在这里帮我整理了这一点,我失去了一些东西在这里

can anyone here help me to sort this out am i missing something here

感谢您的帮助

推荐答案

的addAction()加入API等级16;安卓4.0.4运行API 15级更换为 NotificationCompat.Builder 从Android支持包,或者只调用的addAction()如果 Build.VERSION.SDK_INT> = Build.VERSION_ codeS.JELLY_BEAN

addAction() was added to API Level 16; Android 4.0.4 runs API Level 15. Either switch to NotificationCompat.Builder from the Android Support package, or only call addAction() if Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN.

这篇关于java.lang.NoSuchMethodError:android.app.Notification $ Builder.addAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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