8
Tôi có vấn đề MainActivity của tôi có thể được tạo theo 3 cách: 1) khởi động standart App 2) từ Dịch vụ 3) từ nhấp chuột thông báo. Làm cách nào để kiểm tra thời điểm bắt đầu từ lần nhấp thông báo?Cách kiểm tra xem Hoạt động có bắt đầu từ thông báo
mã thông báo:
private void createNotification()
{
Log.d("service createNotification",MainActivity.TAG);
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this,MainActivity.class);
intent.putExtra(AppNames.IS_NOTIFICATION_INTENT,true);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(this.getString(R.string.notification_title))
.setContentText(this.getString(R.string.notification_text))
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher);
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(AppNames.APP_NOTIFICATION, builder.getNotification());
}
unfochnately phương thức này không hoạt động, Luôn nhận được thông báo trong cả 3 trường hợp. – Abbath
bạn cần thay đổi "thông báo" trong putExtra thành một thứ khác, thành "dịch vụ" chẳng hạn. –
không hoạt động, hãy xem @http: //stackoverflow.com/questions/14122085/determine-if-activity-is-called-by-a-notification nếu any1 quan tâm –