Net*_*ter 6 android android-notifications
我开发了一个Android应用程序,我在应用程序启动时使用了通知
当我在Android模拟器上运行代码时,应用程序工作正常,当我尝试在Android版本为4.0.4的真实设备上运行相同的时候
它在logcat中抛出了我的错误
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)
Run Code Online (Sandbox Code Playgroud)
我试过的代码是,
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);
Run Code Online (Sandbox Code Playgroud)
这里有人可以帮我解决这个问题吗?
谢谢你的帮助
Com*_*are 16
addAction()已添加到API级别16; Android 4.0.4运行API级别15.要么NotificationCompat.Builder从Android支持包切换到,要么只调用addAction()if Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN.
| 归档时间: |
|
| 查看次数: |
11141 次 |
| 最近记录: |