安卓支付

2018-04-12  本文已影响0人  Kyle_An

调用里面的方法就可以了

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.UI;
public class Android_share : MonoBehaviour
    {
    public Button Android_shareButton;

    void Start()
    {
        Android_shareButton.onClick.AddListener(Share);
    }

        /// <summary>
        /// 安卓原生分享
        /// </summary>
        public void Share()
        {
            #if UNITY_ANDROID && !UNITY_EDITOR
            //定义AndroidJavaClass变量
            AndroidJavaClass UnityPlayer;
            AndroidJavaClass Intent;
            AndroidJavaClass Uri;
            AndroidJavaClass Environment;

            //实例化AndroidJavaClass变量
            UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            Intent = new AndroidJavaClass ("android.content.Intent");
            Uri = new AndroidJavaClass ("android.net.Uri");
            Environment = new AndroidJavaClass ("android.os.Environment");

            AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

            AndroidJavaObject jstr_type = new AndroidJavaObject("java.lang.String", "text/plain");
        //    AndroidJavaObject jstr_content = new AndroidJavaObject("java.lang.String", "https://play.google.com/store/apps/details?id= " + Application.identifier);
            AndroidJavaObject jstr_content = new AndroidJavaObject("java.lang.String", "https://blog.csdn.net/LIQIANGEASTSUN/article/details/78835238");

            AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", Intent.GetStatic<AndroidJavaObject>("ACTION_SEND"));
            intent.Call<AndroidJavaObject>("setType", jstr_type);
            intent.Call<AndroidJavaObject>("putExtra", Intent.GetStatic<AndroidJavaObject>("EXTRA_TEXT"), jstr_content);

            currentActivity.Call("startActivity", intent);

            #endif
        }
    }
上一篇下一篇

猜你喜欢

热点阅读