Scenario :Launch the App, SignUp and Logout for 20 users. After Sign Up it is going to ask all permissions for the first time, I should "Allow" all the permissions and Click on some other elements then Logout. For 2nd I need accept only if it is present o

Scenario :Launch the App, Sign Up and Logout for 20 users. After Sign Up it is going to ask all permissions for the first time, I should “Allow” all the permissions and Click on some other elements then Logout. For 2nd I need accept only if it is present otherwise I should on next element which i have given. It is Clicking on “Allow” only if it is present for the first time but in second time “Allow” will not be there so it should click on next element but it is not clicking.

Please help me to find solution.
Can any one tell me the Solution.

public void tapOnAllow() { //5
try {
AndroidElement allow = driver.findElementByXPath("//android.widget.Button[@text=‘Allow’]");
//System.out.println(allow.isDisplayed());
if(allow.isDisplayed()) {
for(int i=0;i<5;i++) {
touch.tap(tapOptions().withElement(element(allow))).perform();

				}
			}
	} catch (Exception e) {
		
	}
	

}

public void tapOnLater() throws InterruptedException {
	
	//driver.findElementByAndroidUIAutomator("text(\"I'll do this later.\")").click();
	AndroidElement later = driver.findElementByAndroidUIAutomator("text(\"I'll do this later.\")");
	touch.tap(tapOptions().withElement(element(later))).perform();
	Thread.sleep(2000);
}