对于类型通知,未定义setLatestEventInfo(...)

时间:2015-11-27 10:16:44

标签: android

我知道" setLatestEventInfo"已弃用。但我必须使用它来与api lv 8设备兼容,因为新的通知调用功能与api 8设备不兼容。

我使用" setLatestEventInfo"在一些proyects中,我得到了一个弃用的警告,但是在这个新的项目中,我得到了#34;未定义类型Notification"

Notification note = new   Notification(R.drawable.abc_ic_go_search_api_mtrl_alpha,
                "", System.currentTimeMillis());
        Intent intent;


            intent = new Intent(context, MainActivity.class);


        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
  

note.setLatestEventInfo(context,"","",pi);

        note.flags |= Notification.FLAG_NO_CLEAR;

        ((Service) context).startForeground(1337, note);

如果我使用Notification.Builder:

  

调用需要API级别11(当前最小值为8):new   android.app.Notification.Builder

2 个答案:

答案 0 :(得分:5)

解决了从Android api 6.0更改为5.1.1的项目属性。

答案 1 :(得分:0)

让我们尝试实现通知:

        Intent intent = new Intent("com.example.notitfications.MYNOTIFICATION");

        PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 1, intent, 0);

        Notification.Builder builder = new Notification.Builder(MainActivity.this);

        builder.setAutoCancel(false);
        builder.setTicker("Ticker text");
        builder.setContentTitle("Content of Notification");               
        builder.setContentText("You have a new message");
        builder.setSmallIcon(R.drawable.ic_launcher);
        builder.setContentIntent(pendingIntent);
        builder.setOngoing(true);
        builder.setSubText("This is subtext...");   //API level 16
        builder.setNumber(100);
        builder.build();

        myNotication = builder.getNotification();
        manager.notify(11, myNotication);