[RESOLU] Lancement d'une appli Android depuis une autre

Toutes les questions sur le développement Mobile, y compris la partie script.
Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

[RESOLU] Lancement d'une appli Android depuis une autre

Message par Paullux » 02 Juin 2018 11:22

Bonjour à tous,

Pourquoi avec ce code :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class HUB : MonoBehaviour {


    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void Quitter()
    {
        Application.Quit();
    }

    public void OuvrirPageWeb (string PageWeb)
    {
        Application.OpenURL(PageWeb);
    }
    
    public void launchApp(string packageName)
    {
        bool fail = false;
        string bundleId = packageName;  
        AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");

        AndroidJavaObject launchIntent = null;
        try
        {
            launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
        }
        catch (System.Exception e)
        {
            fail = true;
        }

        if (fail)
        { //open app in store
            Application.OpenURL("market://details?id=" + packageName);
        }
        else //open the app
            ca.Call("startActivity", launchIntent);

        up.Dispose();
        ca.Dispose();
        packageManager.Dispose();
        launchIntent.Dispose();
    }
}
Pourquoi si une application demandée n'est pas installée il ne m'envoie pas sur le play store ??
Dernière édition par Paullux le 02 Juin 2018 11:46, édité 1 fois.
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

[RESOLU] Re: Lancement d'une appli Android depuis une autre

Message par Paullux » 02 Juin 2018 11:46

Résolu :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class HUB : MonoBehaviour {


    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void Quitter()
    {
        Application.Quit();
    }

    public void OuvrirPageWeb (string PageWeb)
    {
        Application.OpenURL(PageWeb);
    }
    
    public void launchApp(string packageName)
    {
        bool fail = false;
        string bundleId = packageName;  
        AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");

        AndroidJavaObject launchIntent = null;
        try
        {
            launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
        }
        catch (System.Exception e)
        {
            fail = true;
        }

        if (launchIntent == null) Application.OpenURL("market://details?id=" + packageName);
        
        if (fail)
        { //open app in store
            //Application.OpenURL("market://details?id=" + packageName);
        }
        else //open the app
            ca.Call("startActivity", launchIntent);

        up.Dispose();
        ca.Dispose();
        packageManager.Dispose();
        launchIntent.Dispose();
    }
}
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Répondre

Revenir vers « Développement plateformes mobile Iphone et Android »