android notification action example

w‮ual.ww‬tturi.com
android notification action example

how to create a notification with action in android:

public class ActionReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {

		//Toast.makeText(context,"recieved",Toast.LENGTH_SHORT).show();

		String action=intent.getStringExtra("action");
		if(action.equals("action1")){
			performAction1();
		}
		else if(action.equals("action2")){
			performAction2();

		}
		//This is used to close the notification tray
		Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
		context.sendBroadcast(it);
	}

	public void performAction1(){

	}

	public void performAction2(){

	}
}
Created Time:2017-08-31 08:34:00  Author:lautturi