package net.sanukin;

import android.content.pm.PackageManager;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;

/**
 * Created by sanuki.wataru on 2016/05/18.
 */
public class OverrideUnityActivity extends UnityPlayerActivity {

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        switch (requestCode) {
            case 0: {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    UnityPlayer.UnitySendMessage("UniAndroidPermission", "OnPermit", "");
                } else {
                    UnityPlayer.UnitySendMessage("UniAndroidPermission", "NotPermit", "");
                }
                break;
            }
        }
    }
}

@@ -559,258 +559,577 @@
     
-UnityPlayer.UnitySendMessage(%22UniAndroidPermission%22, %22OnPermit%22, %22%22);%0A                %7D else %7B%0A                    UnityPlayer.UnitySendMessage(%22UniAndroidPermission%22, %22NotPermit%22, %22%22);%0A                %7D%0A                break;%0A            %7D%0A        %7D
+SendRequestResultToUnity(%22OnPermit%22);%0A                %7D else %7B%0A                    if(permissions.length %3E 0 && shouldShowRequestPermissionRationale(permissions%5B0%5D)) %7B%0A                        SendRequestResultToUnity(%22NotPermit%22);%0A                    %7D else %7B%0A                        SendRequestResultToUnity(%22NotPermitAndCheckNeverAskAgain%22);%0A                    %7D%0A                %7D%0A                break;%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void SendRequestResultToUnity(String result)%7B%0A        UnityPlayer.UnitySendMessage(%22UniAndroidPermission%22, result, %22%22);
 %0A   

update android project to support never ask again option