有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

    首先,我们应该创建调用活动的通知:

    Intent intent = new Intent(this, YourClass.class);
    intent.putExtra("NotiClick",true);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        Notification Noti;
        Noti = new Notification.Builder(this)
                .setContentTitle("YourTitle")
                .setContentText("YourDescription")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentIntent(pIntent)
                .setAutoCancel(true).build();
    
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    
        notificationManager.notify(0, Noti);
    }
    

    然后在类的onCreate()中执行以下操作:

    Bundle extras = getIntent().getExtras();
    
    if(extras == null) 
    {
        //not being clicked on
    } 
    else if (extras.getBoolean("NotiClick"))
    {
        //being clicked
    }
    

    对于完全封闭的应用程序,您可以终止进程:

    android.os.Process.killProcess(android.os.Process.myPid());