我目前正在尝试将实时麦克风音频从Android设备传输到Java程序.我开始在两个Android设备之间发送实时音频,以确认我的方法是正确的.在接收设备上几乎没有任何延迟,可以完美地听到音频.接下来,我将相同的音频流发送到一个小型Java程序,我验证了数据也正确地发送到这里.现在我想要做的是编码这些数据,并以某种方式在运行Java程序的服务器上播放它.我宁愿在使用HTML5或JavaScript的网络浏览器中播放它,但我愿意接受其他方法,如VLC.
以下是发送实时麦克风音频的Android应用程序的代码
public class MainActivity extends Activity {
private Button startButton,stopButton;
public byte[] buffer;
public static DatagramSocket socket;
AudioRecord recorder;
private int sampleRate = 44100;
private int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
private boolean status = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startButton = (Button) findViewById (R.id.start_button);
stopButton = (Button) findViewById (R.id.stop_button);
startButton.setOnClickListener(startListener);
stopButton.setOnClickListener(stopListener);
minBufSize += 2048;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true; …Run Code Online (Sandbox Code Playgroud) 我最近开始考虑使用Appium进行一些功能测试.我想通过gradle通过Android studio运行Appium测试.
有没有人试图这样做,如果有的话,你可以给我一些关于设置的信息,比如使用什么gradle任务等.
我在构建文件中包含了必要的依赖项:
androidTestCompile( 'io.appium:Java的客户机:2.0.0')
我下面有一个示例测试,我只需要一种通过gradle运行它的方法:)
package com.appium.trial;
import junit.framework.Assert;
import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class TrialTest {
private static WebDriver wd;
@Before
public void setUp() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("deviceName", "Samsung Galaxy S4 - 4.2.2 - API 17 - 1080x1920");
capabilities.setCapability("app", "/Users/chuckster/Documents/Dev/AppiumTrial/appium-trial.apk");
capabilities.setCapability("appPackage", "com.appium.trial");
capabilities.setCapability("appActivity", "com.appium.trial.TrialTest");
try {
wd = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); …Run Code Online (Sandbox Code Playgroud) 在运行5.0的Android设备上查看我的应用时,我注意到了一个奇怪的错误.
在5.0之前的设备上,我的应用会在必要时将逗号添加到数字中.例如"1,234"或"100,000"
在5.0设备上,相同的代码将这些数字显示为"1234"或"100000".有没有其他人注意到这一点?
我已经包含了我的代码来格式化下面的数字 - 我不确定需要更改棒棒糖设备以显示正确的格式.
public static String formatNumber(Integer number, String prefix) {
if (prefix == null) {
prefix = Constants.PREFIX_SYMBOL;
}
StringBuilder stringBuilder = new StringBuilder(prefix);
NumberFormat numberFormatter = NumberFormat.getIntegerInstance(new Locale("en_UK"));
stringBuilder.append("").append(numberFormatter.format(number));
return stringBuilder.toString();
}
Run Code Online (Sandbox Code Playgroud) 我目前正在为我的项目实现Android的Fest,但我似乎遇到了依赖问题.如果我在没有包含Fest库的情况下运行测试,测试将正常运行.一旦我添加了Fest库,那么测试就不再运行了.而是抛出异常.
我的项目使用以下依赖项:
compile files('libs/robotium-solo-5.1.jar')
androidTestCompile 'com.squareup:fest-android:1.0.8'
androidTestCompile 'com.google.code.gson:gson:2.2.4'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile 'com.google.mockwebserver:mockwebserver:20130706'
androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.0') {
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
exclude module: 'mockito-core'
}
androidTestCompile 'org.mockito:mockito-all:+'
Run Code Online (Sandbox Code Playgroud)
我已经尝试排除我在下面列出的Fest Android依赖项,但它对测试的运行没有影响.
androidTestCompile ('com.squareup:fest-android:1.0.8') {
exclude group: 'com.google.android', module: 'android'
exclude group: 'com.google.android', module: 'support-v4'
exclude group: 'org.easytesting', module: 'fest-assert-core'
}
Run Code Online (Sandbox Code Playgroud)
这是在包含Fest库的情况下运行测试时发生的异常.
junit.framework.AssertionFailedError: Exception in constructor: testClickActionBarItems (java.lang.NoClassDefFoundError: com.example.android.activities.SectionsActivity
at com.example.android.test.activities.SectionsEspressoTests.<init>(SectionsEspressoTests.java:21)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:118)
at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:148)
at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:56)
at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80)
at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:444)
at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:425)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:114) …Run Code Online (Sandbox Code Playgroud) android fest android-testing android-studio android-gradle-plugin