Ok, I have checked this again. It works, every time you call this function it will change your orientation. Maybe, you can customize it to have more control over which orientation you want (Like sensor). A lot of cleaning work needs to be done as it is amateurish One thing that I forgot to mention was the imports, your imports in the APL file should look like this -
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.google.android.gms.common.ConnectionResult;
import android.telephony.TelephonyManager;
import android.provider.Settings.Secure;
import android.net.wifi.WifiManager;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import android.content.pm.ActivityInfo;