小编lan*_*nyf的帖子

在Espresso中,如何选择具有相同id的视图以避免AmbiguousViewMatcherException

有gridView有一些图像.gridView的单元格来自相同的预定义布局,具有相同的id和desc.

R.id.item_image == 2131493330

onView(withId(is(R.id.item_image))).perform(click());
Run Code Online (Sandbox Code Playgroud)

由于网格中的所有单元都具有相同的id,因此它得到了AmbiguousViewMatcherException.如何选择第一个或其中任何一个?谢谢!

android.support.test.espresso.AmbiguousViewMatcherException:'id:is <2131493330>'匹配层次结构中的多个视图.问题视图在下方标有"****MATCHES****".

+ -------------> ImageView {id = 2131493330,res-name = item_image,desc = Image,visibility = VISIBLE,width = 262,height = 262,has-focus = false,has -focusable = false,has-window-focus = true,is-clickable = false,is-enabled = true,is-focused = false,is-focusable = false,is-layout-requested = false,is-selected = false ,root-is-layout-requested = false,has-input-connection = false,x = 0.0,y = 0.0}****MATCHES****

+ -------------> ImageView {id = 2131493330,res-name = item_image,desc = Image,visibility = VISIBLE,width = 262,height = 262,has-focus = false,has -focusable = false,has-window-focus = true,is-clickable = false,is-enabled = …

android android-espresso

44
推荐指数
7
解决办法
4万
查看次数

为什么NotificationManagerCompat :: cancelAll()获取SecurityException?

使用NotificationManagerCompat取消所有通知.

NotificationManagerCompat manager =  
    NotificationManagerCompat.from(ctx.getApplicationContext());
manager.cancelAll();
Run Code Online (Sandbox Code Playgroud)

它有一段时间异常(大部分时间都有效).

在Andoid 6上:

java.lang.SecurityException:Permission Denial:来自pid = 22994的getCurrentUser(),uid = 10184需要android.permission.INTERACT_ACROSS_USERS

Fatal Exception: java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=22994, uid=10184 requires android.permission.INTERACT_ACROSS_USERS
   at android.os.Parcel.readException(Parcel.java:1602)
   at android.os.Parcel.readException(Parcel.java:1555)
   at android.app.INotificationManager$Stub$Proxy.cancelAllNotifications(INotificationManager.java:649)
   at android.app.NotificationManager.cancelAll(NotificationManager.java:323)
   at android.support.v4.app.NotificationManagerCompat.cancelAll(NotificationManagerCompat.java:197)
Run Code Online (Sandbox Code Playgroud)

在Android 5.0,4.4.2上:

ava.lang.SecurityException:权限拒绝:来自pid = 5460的getIntentSender(),uid = 10135,(需要uid = 1000)不允许在android.os.Parcel.readException(Parcel.java:1465)中作为包android发送

Fatal Exception: java.lang.SecurityException: Permission Denial: getIntentSender() from pid=3109, uid=10153, (need uid=1000) is not allowed to send as package android
   at android.os.Parcel.readException(Parcel.java:1472)
   at android.os.Parcel.readException(Parcel.java:1426)
   at android.app.INotificationManager$Stub$Proxy.cancelAllNotifications(INotificationManager.java:271)
   at android.app.NotificationManager.cancelAll(NotificationManager.java:220)
   at android.support.v4.app.NotificationManagerCompat.cancelAll(NotificationManagerCompat.java:197)
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 可能是什么原因?
  2. 这里有什么身份证?难道ctx.getApplicationContext().getApplicationInfo().uid …

android android-notifications android-securityexception android-binder

27
推荐指数
2
解决办法
2379
查看次数

在Kotlin中使用Gson来解析JSON数组

试图在Kotlin中解析JSON数组,使它适用于单个JSON对象到WeatherObject对象(下面的代码片段)

{
"coord": {
    "lon": -2.93,
    "lat": 43.26
},

"weather": [{
    "id": 802,
    "main": "Clouds",
    "description": "scattered clouds",
    "icon": "03d"
}],

"main": {
    "temp": 283.681,
    "temp_min": 283.681,
    "temp_max": 283.681,
    "pressure": 991.72,
    "sea_level": 1034.92,
    "grnd_leve": 991.72,
    "humidity": 98
},
"wind": {
    "speed": 1.07,
    "deg": 144.001
},

"dt": 1429773245,
"id": 3128026,
"name": "Bilbao",
"cod": 200
Run Code Online (Sandbox Code Playgroud)

}

但如果JSON是一个具有相同JSON对象的数组,即不确定如何做同样的事情

从json数组[{},{} ...]到ArrayList <WeatherObject>

就像是:

fun getWeatherObjectArrayFromJson(jsonStr: String): ArrayList&lt;WeatherObject &gt
Run Code Online (Sandbox Code Playgroud)

有问题的gsonBuilder.registerTypeAdapter(ArrayList <WeatherObject> :: class.java,WeatherDeserializer())

class WeatherObject {

    var main: String = ""
    var description: String = …
Run Code Online (Sandbox Code Playgroud)

android gson kotlin json-deserialization

26
推荐指数
1
解决办法
2万
查看次数

mockk,刚刚运行的是什么

找不到有关“just run”的解释,用它存根函数时意味着什么?

它会让模拟对象调用它的真实函数,还是让该函数运行一个不执行任何操作的存根?

是否有示例来展示一些真实的用例?

@Test
fun `mocking functions that return Unit`() {
    val SingletonObject = mockkObject<SingletonObject>()
    every { SingletonObject.functionReturnNothing() } just Runs. // ???

    SingletonObject.otherMemberFunction(). //which internally calls functionReturnNothing()
    //...
}
Run Code Online (Sandbox Code Playgroud)

无论有没有这个every { SingletonObject.functionReturnNothing() } just Runs存根,测试都是一样的。

kotlin mockk

19
推荐指数
1
解决办法
2万
查看次数

为什么有时它会抛出FileNotFoundException

代码大部分时间都有效,但有时会引发异常.无法弄清楚是什么原因造成的.

什么是在...创建文件

/storage/emulated/0/Download/theFileName.jpg

并向其写入数据(来自sourceFile,确实存在),但新创建的文件得到"文件不存在"异常.

(它确实有uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE", and uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"清单").

File sourceFile = new File(theSourceFileFullPath);
if (sourceFile.exists()) {
    File downloadDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    String downloadPath = downloadDirectory.getPath();
    String newFilePath = (downloadPath + "/" + fileName);
    File newFile = new File(newFilePath);
    try {
        FileInputStream in = new FileInputStream(sourceFile);

        // ava.io.FileNotFoundException: 
        //     /storage/emulated/0/Download/theFileName.jpg: open failed: ENOENT (No such file or directory) 
        // exception at this line       
        FileOutputStream out = new FileOutputStream(newFile);
        //......
     } catch (Exception e) {}
}
Run Code Online (Sandbox Code Playgroud)

android filenotfoundexception fileoutputstream

17
推荐指数
1
解决办法
1819
查看次数

在kotlin中flatMap与地图的用例是什么?

https://try.kotlinlang.org/#/Kotlin%20Koans/Collections/FlatMap/Task.kt

它有使用flatMap和的样本map

似乎两者都在做同样的事情,是否有一个样本来显示使用flatMapmap?的区别?

数据类型:

data class Shop(val name: String, val customers: List<Customer>)

data class Customer(val name: String, val city: City, val orders: List<Order>) {
    override fun toString() = "$name from ${city.name}"
}

data class Order(val products: List<Product>, val isDelivered: Boolean)

data class Product(val name: String, val price: Double) {
    override fun toString() = "'$name' for $price"
}

data class City(val name: String) {
    override fun toString() = name
}
Run Code Online (Sandbox Code Playgroud)

样品:

fun Shop.getCitiesCustomersAreFrom(): …
Run Code Online (Sandbox Code Playgroud)

collections kotlin flatmap

15
推荐指数
2
解决办法
1万
查看次数

enter/exit和popEnter/popExit的区别是什么,以及它将在pop堆栈中运行的事务动画

在setCustomAnimations()中,动画需要四个资源ID.不是很了解他们.如果有人有更清晰的图片,如果你能解释,将不胜感激.

假设片段A添加在占位符和后台堆栈中.

FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.holder, fragA, FragmentA.FRAGMENT_NAME);
        ft.addToBackStack(FragmentA.FRAGMENT_NAME);
        ft.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_in_from_top, R.anim.slide_in_from_left, R.anim.slide_in_from_right);
        ft.show(frag);
        ft.commit();
Run Code Online (Sandbox Code Playgroud)

并用片段B替换:

FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.holder, fragB, FragmentB.FRAGMENT_NAME);
        ft.addToBackStack(FragmentB.FRAGMENT_NAME);
        ft.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_in_from_top, R.anim.slide_in_from_left, R.anim.slide_in_from_right);
        ft.show(frag);
        ft.commit();
Run Code Online (Sandbox Code Playgroud)

下次如果做一个popstack()

fm.popBackStackImmediate(FragmentB.FRAGMENT_NAME,
                                FragmentManager.POP_BACK_STACK_INCLUSIVE);
Run Code Online (Sandbox Code Playgroud)

它将运行哪个事务的动画?

/**
 * Set specific animation resources to run for the fragments that are
 * entering and exiting in this transaction. The <code>popEnter</code>
 * and <code>popExit</code> animations will be played for enter/exit
 * operations specifically when popping the back stack.
 */
public abstract FragmentTransaction setCustomAnimations(@AnimRes int …
Run Code Online (Sandbox Code Playgroud)

android fragmenttransaction fragment-backstack

13
推荐指数
1
解决办法
3227
查看次数

修剪字符串函数中的"it ​​<=''"在这里意味着什么

有一个java代码来修剪字符串

String title = titleEt.getText().toString().trim();
Run Code Online (Sandbox Code Playgroud)

当覆盖到kotlin时,我认为这应该是用于修剪前导空间和尾随空间的kotlin代码.

val title = titleEt.text.toString().trim()
Run Code Online (Sandbox Code Playgroud)

但IDE会生成此代码

val title = titleEt.text.toString().trim { it <= ' ' }
Run Code Online (Sandbox Code Playgroud)

这里的{it <=''}是什么,它是否少于''?

android trim kotlin

13
推荐指数
1
解决办法
3687
查看次数

通知会在使用Android 7的Motorola设备上引发RemoteServiceException

在应用程序收到通知然后构建并发布设备通知后,通知在所有其他设备上正常工作,但不适用于摩托罗拉的设备,如Moo Z Droid,DROID Turbo2,Moto G(4)Plus,Moto G(5)Plus等.只有OS> 7.

有没有人注意到摩托罗拉设备os> 7的同样问题?

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package pkg=com.app.packagename: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.app.packagename ……)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6154)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Run Code Online (Sandbox Code Playgroud)

android motorola push-notification

11
推荐指数
0
解决办法
379
查看次数

如何设置textview width wrap_content但限制为父宽度的1/3

有一个TextView,它的宽度不应超过其父宽度的1/3.如果它的宽度小于父级的1/3,它应该有wrap_content行为.它的横向兄弟将始终在它旁边开始.

尝试下面,它总是有1/3和2/3的硬切,所以如果text1的空间小于1/3,则TextView两个不会在它旁边开始.

改变LinearLayoutRelativeLayout,然后android:layout_weight="n"不起作用

基本上,需要定义宽度是wrap_contentmaxWidth不超过1/3.

有什么建议吗?

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">

    <TextView 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"
        android:ellipsize="end"
    />

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:singleLine="true"
        android:ellipsize="end"
        android:layout_weight="2"
    />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android textview android-layout-weight

10
推荐指数
1
解决办法
8842
查看次数