在我的测试案例中,我必须记录1小时,在机器人solo.sleep(600000)完成了我的工作,但在浓缩咖啡中,我对IdlingResource概念感到困惑.我必须开始录音并等待一段时间(取决于测试类型)15分钟,60分钟等.
机器人中的等效代码
solo.clickOnView(solo.getView("start_record"));
solo.sleep(duration * 60 * 1000);
solo.clickOnView(solo.getView("stop_record"));
Run Code Online (Sandbox Code Playgroud)
我尝试在浓缩咖啡中使用它
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AaEspressoTest {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.absd.rec.RecorderActivity";
private static Class<?> launcherActivityClass;
private Solo solo;
private static CoreRecordingTest skyroTestRunner;
private static Class<? extends Activity> activityClass;
static {
try {
activityClass = (Class<? extends Activity>) Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Rule
public final ActivityTestRule<?> activityRule
= new ActivityTestRule<>(activityClass);
private IntentServiceIdlingResource idlingResource;
@Before
public void registerIntentServiceIdlingResource() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); …Run Code Online (Sandbox Code Playgroud) 这是我第一次使用espresso意图,我按照Android测试项目中提供的IntentsBasicSamle但没有解决.
在我的应用程序中,我有一个活动,用户选择多个图像然后返回的图像显示在gridview中,现在通过使用espresso意图我想模拟这个而不去实际的图像选择器并每次返回一些指定的图像.
没有错误,但在我运行测试时仍会打开图像选择器窗口.我觉得我做错了,但我没有得到它是如何工作的.
我正在测试使用apk.
这就是照片选择器的调用方式
应用代码
这就是我调用选择图像的方式Intent和结果在onActivityResult中处理.
if (ApiUtils.checkApiLevel(18)) {
//API18+
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, getActivity().getString(R.string.fragment_image_selection_select_picture)), 1);
Run Code Online (Sandbox Code Playgroud)
测试代码
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ImagesTests {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.company.recorder.RecorderActivity";
private static Class<? extends Activity> activityClass;
private ServiceValidatorIdlingResource serviceValidatorIdlingResource;
static {
try {
activityClass = (Class<? extends Activity>) Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
/**
* Change espresso default view idling time
* so that test can wait for long time …Run Code Online (Sandbox Code Playgroud) java android android-intent android-testing android-espresso
我正在尝试从蓝牙耳机录制音频,startBluetoothSco()在不同版本的android中工作不同,在android 4.2,4.4和5.0上录制来自蓝牙耳机的音频.使用" 诺基亚BH-310和9xxPlantronics "蓝牙耳机.
SAMPLE_RATE = 8000;
AudioSource.DEFAULT
mRecorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT,
bufferSize);
Run Code Online (Sandbox Code Playgroud)
AudioSource.DEFAULT
mRecorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT,
bufferSize);
Run Code Online (Sandbox Code Playgroud)
要么
AudioSource.MIC
mRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT,
bufferSize);
Run Code Online (Sandbox Code Playgroud)
AudioSource.VOICE_COMMUNICATION
mRecorder = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT,
bufferSize);
//with other AudioSource types (MIC, DEFAULT) sco returns connected state but record from phone mic
Run Code Online (Sandbox Code Playgroud)
LOG for Android 5.0设备连接状态
D/inside onRcv? state=0
D/State=? conn -> 0
D/inside onRcv? state=2 …Run Code Online (Sandbox Code Playgroud) 我有一个由ICS用户发送的堆栈跟踪.
在我的Froyo设备上一切正常,但用户显然在AudioManager.startBluetoothSco()调用时获得权限拒绝...我不知道为什么会发生这种情况 - 我知道广播为ACTION_SCO_AUDIO_STATE_CHANGED 是粘性的,但它不是发送的应用程序它,所以它不应该需要许可......
下面是堆栈跟踪:
java.lang.SecurityException: Permission Denial: broadcastIntent() requesting a sticky
broadcast from pid=15341, uid=10064 requires android.permission.BROADCAST_STICKY
at android.os.Parcel.readException(Parcel.java:1327)
at android.os.Parcel.readException(Parcel.java:1281)
at android.media.IAudioService$Stub$Proxy.startBluetoothSco(IAudioService.java:1090)
at android.media.AudioManager.startBluetoothSco(AudioManager.java:975)
at de.bulling.smstalk.libs.utils.AudioUtils.startBluetoothSco(AudioUtils.java:164)
at de.bulling.smstalk.Services.TTS.speakIt(TTS.java:151)
at de.bulling.smstalk.Services.TTS.onInit(TTS.java:83)
at android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:627)
at android.speech.tts.TextToSpeech.access$1000(TextToSpeech.java:52)
at android.speech.tts.TextToSpeech$Connection.onServiceConnected(TextToSpeech.java:1279)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1068)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1085)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
/编辑:我可以重现这个问题,如果我是否启动服务START_STICKY并不重要.
使用我的测试 android 应用程序,我试图计算如果我的用户每 10 秒或 1 分钟添加一个孩子并与 5 个设备同步需要多少带宽。
我的应用程序用户每分钟都会创建数据,因此我必须计算每个用户每月的订阅成本。每个用户每月消耗的大约带宽。
我在 MainActivity 中调用 addChildEventListener 并每 10 秒从 BroadcastReceiver 类中添加子项。
每次我重新启动应用程序时,它都会下载所有行,这意味着消耗带宽。
如何减少带宽使用并使应用程序每次重新启动应用程序时仅检索新添加的子项?
如果我添加 Firebase.getDefaultConfig().setPersistenceEnabled(true); 并且用户在线仍然 addChildEventListener 下载所有数据,它是从服务器下载的还是本地同步的数据?
这就是我正在尝试的。
主活动.java
public class MainActivity extends AppCompatActivity {
Button start, stop;
TextView status;
String url = "https://<my-app>.firebaseio.com/data";
Firebase mFirebaseRef;
AlarmManager alarmManager;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
mFirebaseRef.getDefaultConfig().setPersistenceEnabled(true);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
start = (Button) findViewById(R.id.Start);
stop = (Button) findViewById(R.id.stop);
status = (TextView) findViewById(R.id.serviceText);
mFirebaseRef = new …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用firebase,在调试apk一切正常,但当我更改我的构建类型以释放并签署我的apk并运行应用程序数据未加载我做了什么错误的规则?
无法将调试器附加到发布模式apk,因此无法获得如何调试它.
自定义登录工作正常,我可以使用我的注册电子邮件和密码登录,但数据和图像没有加载.
我登录然后尝试显示数据,我认为调用已经过身份验证
我的数据库和存储规则
存储规则
service firebase.storage {
match /b/example-frienda-backend.appspot.com/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
数据存储规则
{
"rules": {
".read": "auth != null",
".write": "auth != null",
"geofire": {
".indexOn": ["g"],
}
}
}
Run Code Online (Sandbox Code Playgroud) android firebase firebase-security firebase-realtime-database firebase-storage
对于 Facebook 类型的社交网络应用程序,需要一个高性能的数据库结构,用于在 Firebase(Cloud Firestore) (NoSQL) 中存储数据。
要存储的数据:
- Userinfo (name, email etc)
- Friends
- Posts
- Comments on posts.
Run Code Online (Sandbox Code Playgroud)
我对以下两个关于查询性能的数据库结构感到困惑(如果数据库变得巨大)。
(参考:C_xxx 是收藏,D_xxx 是文档)
结构 1
C_AllData
- D_UserID-1
name: xxxx,
email: yyy,
friends: [UserID-3, UserID-4]
- C_Posts
- D_PostId-1
Text: hhh
Date: zzz
- C_Comments
- D_CommentId-1
UserID: 3
Text: kkk
- D_CommentId-2
UserID: 4
Text: kkk
- D_PostId-2
Text: hhh
Date: zzz
- C_Comments
- D_CommentId-3
UserID: 3
Text: kkk
- D_CommentId-4
UserID: 4
Text: kkk
- …Run Code Online (Sandbox Code Playgroud) 我有listview的自定义布局,我想点击列表视图项中的imageview,列表视图中第一项的溢出图标.
我想点击ID为"rcOverflow"的最后一张imageview
我的布局,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingTop="5dp">
<ImageView
android:id="@+id/rcCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/rcTime"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="right"
android:maxLines="1"
android:textColor="#ffffff"
android:textSize="13sp" />
<RelativeLayout
android:id="@+id/rsBubble"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/recordsMonthHeader"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<ImageView
android:id="@+id/rcImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_alignParentTop="true"
android:visibility="gone"
android:layout_marginLeft="3dp"
android:layout_marginRight="4dp"/>
<TextView
android:id="@+id/rcFilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:textColor="#000000"
android:maxLines="2"
android:ellipsize="end"
android:textSize="15sp" />
<TextView
android:id="@+id/rcDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/recordsFilename"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:textColor="#a09f9f" />
<ImageView
android:id="@+id/records_location_image"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignBottom="@id/recordsDuration"
android:layout_marginBottom="4dp" />
<TextView
android:id="@+id/rcLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/recordsDuration"
android:layout_marginBottom="1dp"
android:layout_marginLeft="3dp" …Run Code Online (Sandbox Code Playgroud) Kit-Kat问题无法写入外部SD卡,
如 Goolge文档中所述 为了简化运行KITKAT或更早版本的设备上的代码,您可以使用fromFile(File)模拟DocumentsProvider的行为 下面的代码(New API)适用于Lollipop,但如何使用kitkat的新API?
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, 42);
}
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if (resultCode == RESULT_OK) {
Uri treeUri = resultData.getData();
DocumentFile pickedDir = DocumentFile.fromFile(new File("/mnt/extSdCard/Test"));
// List all existing files inside picked directory
for (DocumentFile file : pickedDir.listFiles()) {
Log.d("Tag", "Found file " + file.getName() + " with size " + file.length()); …Run Code Online (Sandbox Code Playgroud) 我发布一些事件和订阅代码在调试apk上正常工作,但当我用我的密钥库签署apk并安装应用程序时相同的代码崩溃.
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.example.friendz/com.example.friendz.shivaraj.activities.MainActivity}:
a.a.a.h: Subscriber class com.example.friendz.shivaraj.activities.MainActivity
and its super classes have no public methods with the @Subscribe annotation
Run Code Online (Sandbox Code Playgroud)
但是我的主要活动是定义了@Subscribe的订阅者
我的活动中有这个订阅者
@Subscribe
public void updateLocationEvent(String isStartLoc) {
Log.d("eventbuus", "stop event rcvd");
if (isStartLoc.equals("start")) {
startLocationUpdates();
} else {
stopLocationUpdates();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在注册和取消注册这样的
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
EventBus.getDefault().register(this);
}
@Override
protected void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
Run Code Online (Sandbox Code Playgroud) 我正在从机器人切换到浓缩咖啡,我正在使用apk编写测试,我无法访问代码.在使用solo.getView("view-id")的robotium中,我们可以访问视图,但我不知道如何在浓缩咖啡中进行操作?espresso witId()方法需要R.id.viewid,我无权访问.
public class AaEspressoTest {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.tri.re.CordActivity";
private static Class<?> launcherActivityClass;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Rule
public ActivityTestRule<?> mActivityRule = new ActivityTestRule(launcherActivityClass);
@Test public void testHello() throws Exception{
onView(withText("Browse older recordings")).perform(click());
//Id is not accessible shows red
onView(withId(R.id.button)).perform(click());
}
}
Run Code Online (Sandbox Code Playgroud) 我想明确地添加一个谷歌帐户.我会提供用户名和密码.
我刚刚通过这个问题调用者uid XXXX与验证者的uid不同 但我没有得到解决方案.什么是uid?你比较的是哪个.
我在尝试
AccountManager mgr = (AccountManager)getSystemService(ACCOUNT_SERVICE);
Account acc = new Account("xxxj@gmail.com", "com.google");
if(mgr.addAccountExplicitly(acc, "Password", new Bundle()))
{
//account added successfully
//do whatever is needed;
showToast("added");
}
else {
//something did not work
}
Run Code Online (Sandbox Code Playgroud)
错误:调用者uid 10782与身份验证者的uid不同.
这是什么意思?我该如何纠正呢?
任何人请告诉我如何解决这个完整的代码将是非常有帮助的.