基本信息
源码名称:android 对讲机 实例源码下载
源码大小:0.88M
文件格式:.rar
开发语言:Java
更新时间:2017-05-04
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍



package com.bighead.dualspeak;


import com.bighead.chatme.utils.Constant;
import com.bighead.chatme.utils.LogPrint;
import com.bighead.chatme.utils.Util;
import com.example.dualspeak.R;

import android.os.Bundle;
import android.os.IBinder;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

	
	
	private boolean isspeak = false;
	private TextView  waitText = null;
	private TextView  IP_my = null;
	
	private EditText  IP_other = null;
	
	LogPrint logPrint = new LogPrint(this);
	AudioService audioService = null;
	Intent serviceIntent = null;
	public int count = 1;
	private String localip = null;
	private String netIp = null;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		localip = Util.getLocalIp();
		netIp = Util.getNetIp();
		waitText = (TextView) findViewById(R.id.waitText);
		IP_my = (TextView) findViewById(R.id.IP_my);
		IP_my.append(localip "\\" netIp);
		
		IP_other = (EditText) findViewById(R.id.IP_other);
		IP_other.setText(localip);
		
		serviceIntent = new Intent(this, AudioService.class);
		bindService(serviceIntent, sConnection, BIND_AUTO_CREATE);
	}
	
	public void speak(View v){
		if(isspeak){
			try {
				
				v.setBackgroundResource(R.drawable.btn_speak_normal);
				isspeak = false;
				audioService.StopAudio();
				Constant.isStopTalk = false;
				
				waitText.setText("被重置完成~再次语音再次点击");
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			
		}else {
			try {
				
				isspeak = true;
				Constant.isStopTalk = true;
				String ip = IP_other.getText().toString();
				if(!Util.isIP(ip)){
					logPrint.toast("不是一个ip");
					return;
				}
				waitText.setText("等待中......");
					if(audioService == null){
						waitText.setText("空");
						return;
					}
				audioService.StartAudioPlay();
				audioService.StartAudioSend(ip);
				
				waitText.setText("等待完毕,你现在可以说话啦");
				v.setBackgroundResource(R.drawable.btn_speak_pressed);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Constant.isStopTalk = false;
		unbindService(sConnection);
	}
	/**
	 * MainService服务与当前Activity的绑定连接器
	 */
	private ServiceConnection sConnection = new ServiceConnection() {
		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			audioService = ((AudioService.ServiceBinder) service).getService();
		}

		@Override
		public void onServiceDisconnected(ComponentName name) {
			audioService = null;
		}
	};
}