zoukankan      html  css  js  c++  java
  • Unity发送短信

      闲来无事,觉得用uinity来发送短信挺有意思的,所以自己差了点资料,看看能否实现,结果还真的可以!废话不多说,直接码!

    1,新建一空工程,我们就简单的使用UGUI搭建一个丑陋的界面吧!

    2,界面极其简单,直接写发送函数。

    先创建一个AndroidJavaClass 对象,它用来调用jar包里的函数。

     ajc = new AndroidJavaClass("com.qyxls.sms.SMSActivity");

    3,全部代码:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    
    public class SendMessage : MonoBehaviour
    {
        public InputField number;
        public InputField content;
        public Button btn_send;
        public Text statue;
    
        private AndroidJavaClass ajc;
    
        // Use this for initialization
        void Start()
        {
            ajc = new AndroidJavaClass("com.qyxls.sms.SMSActivity");
            btn_send.onClick.AddListener(delegate()
            {
                this.SendMsg(btn_send.gameObject);
            });
        }
    
        void SendMsg(GameObject go)
        {
            if (string.IsNullOrEmpty(number.text) || string.IsNullOrEmpty(content.text))
            {
                statue.text = "信息发送失败!";
                return;
            }
            ajc.CallStatic("SMSSend", new string[] { number.text, content.text });
            statue.text = "信息已发送!";
            StartCoroutine(ChangeStatue());
        }
    
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
                Application.Quit();
        }
    
        private IEnumerator ChangeStatue()
        {
            yield return new WaitForSeconds(1f);
            statue.text = "";
            number.text = "";
            content.text = "";
        }
    
    }

    4,修改图标,简单粗暴直接修改AndroidManifest文件。

    5,真机测试。

    测试结果:问候一下10086吧!

    静待10s,好了。

    工程代码:git@github.com:wuzhangwuzhang/UnitySendMsg.git

  • 相关阅读:
    android 图片加载库 Glide 的使用介绍
    Android Glide数据更新及内存缓存、硬盘缓存清理
    Android中<meta-data>的使用
    分层,工厂模式,依赖注入控制反转
    Asp.Net_Web身份验证
    aspx后缀映射成html
    网站跳舞人代码
    Sqlerver_各类函数
    Sqlserver_时间用法
    Sqlserver_视图
  • 原文地址:https://www.cnblogs.com/wuzhang/p/wuzhang20160306.html
Copyright © 2011-2022 走看看