Home > Mobile >  NotificationCompat can't use
NotificationCompat can't use

Time:09-18

In the code I use NotificationCompat, but NotificationCompat always appear horizontal line, also have no effect after operation, my android version is 3.0.1

The import android. Support. The v4. App. NotificationCompat;
,,,,,,
Public class MainActivity extends AppCompatActivity implements the View. An OnClickListener {
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_main);
The Button sendNotice=(Button) the findViewById (R.i d.s end_notice);
SendNotice. SetOnClickListener (this);
}

Public void onClick (View v) {
The switch (v.g etId ()) {
Case R.i d.s end_notice:
Intent Intent=new Intent (this, NotificationActivity. Class);
PendingIntent PI=PendingIntent. GetActivity (this, 0, intent, PendingIntent. FLAG_UPDATE_CURRENT);
NotificationManager manager=(NotificationManager) getSystemService (NOTIFICATION_SERVICE);
NotificationCompat. Builder Builder=new NotificationCompat. Builder (this);
Notification Notification=builder. SetSmallIcon (R.m ipmap. Ic_launcher)
SetContentTitle (" this is the content title ")
SetContentText (" this is the content text ")
SetWhen (System. CurrentTimeMillis ())
. SetContentIntent (PI)
SetAutoCancel (true)
//. SetDefaults (NotificationCompat DEFAULT_ALL)

.build();
Manager. Notify (1, notification);
break;
Default:
break;

}
}

CodePudding user response:

Horizontal line is the compiler tip you this method is obsolete, you can order into method, annotation will tell you the new alternative is what

CodePudding user response:

Minimum adapter 4.4 Android developers, you now not mobile version

CodePudding user response:

reference z979451341 reply: 3/f
Android development adapted the lowest 4.4 now, can't you mobile version


You mean my android studio version no or my mobile version no?

CodePudding user response:

reference 4 floor linfeng820807 response:
Quote: reference z979451341 reply: 3/f

Android development adapted the lowest 4.4 now, can't you mobile version


Are you referring to my android studio version no or my mobile version no,

My android studio version is 3.0.1, mobile version is 5.1

CodePudding user response:

Notification. Builder mBuilder=new Notification. Builder (this);

CodePudding user response:

Don't know, I give you a project often use Notification tools, high compatible version
https://github.com/linglongxin24/NotificationUtil

CodePudding user response:

Builder method I this has always been not to accept the second parameter, what's the problem??

CodePudding user response:

https://www.cnblogs.com/easy5weikai/p/12596630.html
  • Related