资源简介

unity集成android原生录音(可后台)并实现上传,资源为项目代码压缩包,并非项目工程文件,可根据个人需求自行集成

资源截图

代码片段和文件信息

package com.project.test;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
import com.ideepwise.zhztbusiness.Tools.Tools;
import com.ideepwise.zhztbusiness.Tools.req_multi_form;
import com.unity3d.player.UnityPlayerActivity;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

public class MainActivity extends UnityPlayerActivity {
    public static final int GET_OK = 1GET_ERROR = 2;
    private MyReceiver receiver=null;
    private  boolean isRecording=false;
    private String postURL=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //注册广播接收器
        receiver=new MyReceiver();
        IntentFilter filter=new IntentFilter();
        filter.addAction(“com.ideepwise.zhztbusiness.RecordingService“);
        MainActivity.this.registerReceiver(receiverfilter);

    }

    @Override
    protected void onDestroy(){
        super.onDestroy();
    }

    public void CheckLoaclRecord()
    {
        File file=new  File(Tools.getAudioFilePath());
        if(file.isDirectory())
        {
            File[] files= file.listFiles();
            if(files.length>0)
            {
                try {
                    for (int i = 0; i < files.length; i++) {
                        files[i].delete();
                        }
                    }catch (Exception e)
                        {

                        }
            }
        }
    }
    public void StartRecord(String saleIDString postURL)
    {
        if(isRecording)
            return;
        isRecording=true;
        this.postURL=postURL;
        String startTime=Tools.DateFormat(“yyyy-MM-dd HH:mm:ss“);
//启动Service并传入参数
        Intent intent = new Intent(MainActivity.this RecordingService.class);
        intent.putExtra(“saleID“saleID);
        intent.putExtra(“startTime“startTime);
        startService(intent);
    }
    public void StopRecord()
    {
        Intent intent = new Intent(MainActivity.this RecordingService.class);
        stopService(intent);
    }

    /**
     * 广播接受录音文件存储完后才能上传
     */
    public class MyReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context Intent intent) {
            isRecording=false;
            String recordPath=intent.getExtras().getString(“filePath“);
            UpdateRecord(recordPath);
        }
    }
    // 使用handler处理接收到的消息
    private H

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       10872  2019-01-11 16:24  RecordProject\MainActivity.java
     文件        3343  2019-01-11 16:22  RecordProject\RecordingService.java
     目录           0  2019-01-11 16:20  RecordProject\Tools\
     文件        1058  2019-01-11 16:20  RecordProject\Tools\Tools.java
     文件        1000  2019-01-11 16:20  RecordProject\Tools\req_multi_form.java
     目录           0  2019-01-11 16:20  RecordProject\

评论

共有 条评论