Quantcast
Channel: Actualités – Benoît Freslon
Viewing all articles
Browse latest Browse all 37

Unity – récupérer le volume maximum du téléphone Android sans plugin

$
0
0

Désolé, cet article est seulement disponible en Anglais Américain. Pour le confort de l’utilisateur, le contenu est affiché ci-dessous dans une autre langue. Vous pouvez cliquer le lien pour changer de langue active.

In the previous post we learn how to get the current volume.

As I said the max volume can be different according the OS version or de device.

Now let’s get the max volume in c# without native plugin:

public int GetMaxVolume ()
{
	AndroidJavaObject currentActivity = unityPlayerClass.GetStatic ( "currentActivity" );
	AndroidJavaObject packageManager = currentActivity.Call ( "getPackageManager" );
	AndroidJavaObject context = currentActivity.Call ( "getApplicationContext" );
	AndroidJavaClass audioManagerClass = new AndroidJavaClass ( "android.media.AudioManager" );
	AndroidJavaClass contextClass = new AndroidJavaClass ( "android.content.Context" );
	int AudioManager_STREAM_MUSIC = audioManagerClass.GetStatic<int> ( "STREAM_MUSIC" );
	string Context_AUDIO_SERVICE = contextClass.GetStatic<string> ( "AUDIO_SERVICE" );
	AndroidJavaObject systemService = context.Call<AndroidJavaObject> ( "getSystemService", Context_AUDIO_SERVICE );
	return systemService.Call<int> ( "getStreamMaxVolume", AudioManager_STREAM_MUSIC );
}

The post Unity – récupérer le volume maximum du téléphone Android sans plugin appeared first on Benoît Freslon.


Viewing all articles
Browse latest Browse all 37

Trending Articles