有关 android studio notification 横幅弹出的功能没有反应
小妹在这里已经卡了2-3天了,研究了很多人的文章,
除了低版本api 17有成功外,其他的不是channel null 就是没反应 (channel null已解决)
参考的文章很多,但这主要是这三篇
https://www.twle.cn/l/yufei/a...
https://www.jianshu.com/p/33e...
https://blog.csdn.net/weixin_...
拜托各位大大,帮小妹一下,以下是我的程式跟 gradle, 我在这里卡好久又没有人可问(哭)
![image](/img/bVcL0Qo)
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Context mContext;
private NotificationManager mNManager;
private Notification notify1;
Bitmap LargeBitmap = null;
private static final int NOTIFYID_1 = 1;
private NotificationCompat.Builder builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = MainActivity.this;
LargeBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.app_icon_128x128);
mNManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Button btn_pop_no = (Button) findViewById(R.id.btn_pop_no);
Button btn_clear_no = (Button) findViewById(R.id.btn_clear_no);
NotificationCompat.Builder builder;
}
@Override
public void onClick(View v) {
Log.i("VERION", "onClick: "+ Build.VERSION.SDK_INT);
switch (v.getId()) {
case R.id.btn_pop_no:
if(Build.VERSION.SDK_INT >=26) {
NotificationChannel notificationChannel = new NotificationChannel("braun","braun",NotificationManager.IMPORTANCE_DEFAULT);
mNManager.createNotificationChannel(notificationChannel);
builder = new NotificationCompat.Builder(this,"braun");
}
else {
builder = new NotificationCompat.Builder(this);
}
Intent intent = new Intent(mContext,NotifyDetailActivity.class);
PendingIntent pit = PendingIntent.getActivity(mContext,100,intent,PendingIntent.FLAG_UPDATE_CUR RENT);
builder.setContentTitle("簡單教程").setSubText("簡單教程,簡單編程").setTicker("簡單教程上線啦....")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.app_icon_32x32)
.setLargeIcon(LargeBitmap)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
.setSound(Uri.parse("android.resource://"+getPackageName() +"/"+R.raw.sms))
.setFullScreenIntent(pit,true)
.setAutoCancel(true)
.setContentIntent(pit);
notify1 = builder.build();
mNManager.notify(NOTIFYID_1,notify1);
break; case R.id.btn_clear_no:
mNManager.cancel(NOTIFYID_1);
break; }
}
}
回答
可以参考下我这个开源库
https://github.com/RedTomatoC...
以上是 有关 android studio notification 横幅弹出的功能没有反应 的全部内容, 来源链接: utcz.com/a/83006.html