Search Unity

How to open the Android settings through Unity?

Discussion in 'Android' started by zigglr, Jun 16, 2016.

  1. zigglr

    zigglr

    Joined:
    Sep 28, 2015
    Posts:
    82
    I need to open the notifications setting on Android for my app. Does anyone know how to do this? Thanks
     
  2. ds3427756

    ds3427756

    Joined:
    Dec 6, 2018
    Posts:
    4
    You need to write a tiny iOS plugin for that, here is more information about it: http://docs.unity3d.com/Manual/PluginsForIOS.html

    And here is your solution, ask if something should be unclear.

    Script/Example.cs

    using UnityEngine;

    public class Example
    {
    public void OpenSettings()
    {
    #if UNITY_IPHONE
    string url = MyNativeBindings.GetSettingsURL();
    Debug.Log("the settings url is:" + url);
    Application.OpenURL(url);
    #endif
    }
    }
    Plugins/MyNativeBindings.cs

    public class MyNativeBindings
    {
    #if UNITY_IPHONE
    [DllImport ("__Internal")]
    public static extern string GetSettingsURL();

    [DllImport ("__Internal")]
    public static extern void OpenSettings();
    #endif
    }
    Plugins/iOS/MyNativeBindings.mm

    extern "C" {
    // Helper method to create C string copy
    char* MakeStringCopy (NSString* nsstring)
    {
    if (nsstring == NULL) {
    return NULL;
    }
    // convert from NSString to char with utf8 encoding
    const char* string = [nsstring cStringUsingEncoding:NSUTF8StringEncoding];
    if (string == NULL) {
    return NULL;
    }

    // create char copy with malloc and strcpy
    char* res = (char*)malloc(strlen(string) + 1);
    strcpy(res, string);
    return res;
    }

    const char* GetSettingsURL () {
    NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
    return MakeStringCopy(url.absoluteString);
    }

    void OpenSettings () {
    NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL: url];
    }
    }


    please try it it might help you
    https://crbtech.in/online-android-training-course