大家好,我为 android 应用程序创建了一个通知,我的代码在虚拟设备中工作,但在真实设备中不工作,请帮助我。public void onClick(View v){ try { NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this); builder.setSmallIcon(R.mipmap.smile); builder.setShowWhen(true); builder.setContentText("This is my first notification"); builder.setContentTitle("My Notification"); builder.setAutoCancel(true); Intent i = new Intent(MainActivity.this, SecondClass.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainActivity.this); stackBuilder.addParentStack(SecondClass.class); stackBuilder.addNextIntent(i); PendingIntent pi = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pi); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(0, builder.build()); Toast.makeText(getApplicationContext(),"Notification showed!",Toast.LENGTH_LONG).show(); } catch (Exception e){ Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show(); }}
添加回答
举报
0/150
提交
取消