Unity打包发布后正确读取StreamingAssets文件夹下文件跟调用手机邮箱像指定邮箱地址发邮件

因为项目需要调手机浏览器从StreamingAssets文件夹打开Html文件,花了一天时间查看Unity官方API跟一些论坛帖子,做的一个DEMO
在这里插入图片描述

代码在这里插入代码片
using UnityEngine;
using System.IO;
using UnityEngine.UI;
using System.Collections;

public class NativeShareAndroid : MonoBehaviour
{
public Text waitObject;

public TextAsset fileInfo;

void Awake()
{
  
    StartCoroutine(url());
}





public void OnShareNative()
{//这里是邮箱内容
    string email = "848840773@qq.com";
    string subject = MyEscapeURL("");//邮件预设主题
    string body = MyEscapeURL("");//邮件预设内容
    Application.OpenURL("mailto:" + email + "?subject=" + subject + "&body=" + body);

    waitObject.text = "链接中...";
}
string MyEscapeURL(string url)
{
    //%20是空格在url中的编码,这个方法将url中非法的字符转换成%20格式
    return WWW.EscapeURL(url).Replace("+", "%20");
}
public static string GetPath()
{

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
return “file:///”;
#else
return “file://”;
#endif

}

public void OnMousOPH5()
{
    string filepath = "/TEST.html";
    string path = "";
    if (filepath.EndsWith("html"))
    {
        path = Application.persistentDataPath + filepath;
    }
    else
    {
        path = Application.persistentDataPath + filepath + ".html";
    }
    //直接用附带的浏览器打开Html文件
    Application.OpenURL(path);
}


public IEnumerator url()
{
    yield return new WaitForSeconds(0.5f);//先等待0.5S 等截面渲染出来再执行
    string surl = GetStreamingAssetsPath("TEST.html");
   // Application.streamingAssetsPath + "/TEST.html"



    WWW aa = new WWW(surl);
    Debug.Log(aa);

    yield return aa;

    if (aa.isDone)
    {
        //拷贝数据库到指定路径
        string path = Application.persistentDataPath + "/" + "TEST.html";
        waitObject.text = Application.persistentDataPath;
        File.WriteAllBytes(path, aa.bytes);
    }

  
   
}



public static string fileIsExists(string path)
{
    if (!File.Exists(path))
    {
       
        return "找不到配置文件:" + path;
    }
    else
    {
        return "找到配置文件:" + path;
    }

    
}




public static string GetStreamingAssetsPath(string path)
{//当前系统判断
    if (Application.platform == RuntimePlatform.Android)
    {
        return Application.streamingAssetsPath + "/" + path;
    }
    else if (Application.platform == RuntimePlatform.IPhonePlayer)
    {
        return GetPath() + Application.streamingAssetsPath + "/" + path;
    }
    else if (Application.platform == RuntimePlatform.OSXEditor)
    {
        return GetPath() + Application.streamingAssetsPath + "/" + path;
    }
    else if (Application.platform == RuntimePlatform.WindowsPlayer)
    {
        return "file://" + Application.streamingAssetsPath + "/" + path;
    }
    else if (Application.platform == RuntimePlatform.WindowsEditor)
    {


        ///编辑模式下测试路径
        return Application.streamingAssetsPath + "/" + path;
    }

    return "";
}

}

直接复制拿去吧或者下载DMOE,地址:https://download.csdn.net/download/qq_41111369/11081871

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值