нажмите на уведомление, чтобы открыть новое действие - PullRequest
0 голосов
/ 27 мая 2018

У меня есть уведомление в моем приложении со следующим кодом: Мои уведомления очень хорошо, но моя проблема в том, что я должен сделать, чтобы начать свою основную деятельность после нажатия на мое уведомление.Благодарю.код:

public void run_loop(){
    final Globalv globalv = (Globalv) getApplicationContext();
    RequestQueue requestQueue;
    String url = "https://......./show.php";
    requestQueue = Volley.newRequestQueue(this);
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null ,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONArray jsonArray = response.getJSONArray("allmess");
                        JSONObject respons = jsonArray.getJSONObject(0);
                        String id = respons.getString("id");
                        int lastThread=  Integer.parseInt(String.valueOf(id));
                        if (globalv.getTotal_threads() < lastThread) {
                            globalv.setTotal_threads(lastThread);
                            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
                            builder.setContentTitle("هلالية للغات");
                            builder.setContentText("رسالة جديدة");
                            builder.setSmallIcon(R.drawable.splash_img);
                            builder.setAutoCancel(true);
                            builder.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE);
                            builder.setNumber(1);
                            Notification notification = builder.build();
                            NotificationManager mm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                            mm.cancel(1);
                            mm.notify(1, notification);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("VOLLEY", "ERROR");
        }
    }
    );
    requestQueue.add(jsonObjectRequest);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            run_loop();
        }
    }, 29000);
}

1 Ответ

0 голосов
/ 27 мая 2018

Вам необходимо добавить setContentIntent:

NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
builder.setContentTitle("هلالية للغات");
builder.setContentText("رسالة جديدة");
builder.setSmallIcon(R.drawable.splash_img);
builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE);
builder.setNumber(1);

Intent notificationIntent = new Intent(getApplicationContext(), StartActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
builder.setContentIntent(contentIntent);

Notification notification = builder.build();
NotificationManager mm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mm.cancel(1);
mm.notify(1, notification);
...