小编Jav*_*ana的帖子

如何授予android检测测试的权限?

我有一个读取短信的应用程序.该应用程序在调试时工作正常,但在使用android检测测试时,它会抛出以下错误

java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider
Run Code Online (Sandbox Code Playgroud)

这是我的测试用例

@RunWith(AndroidJUnit4.class)
public class SmsFetcherTest {

   @Test
   public void fetchTenSms() throws Exception {
      // Context of the app under test.
      Context appContext = InstrumentationRegistry.getContext();

      //   Fails anyway.
      //   assertTrue(ContextCompat.checkSelfPermission(appContext,
      //     "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED);

      List<Sms> tenSms = new SmsFetcher(appContext)
              .limit(10)
              .get();

      assertEquals(10, tenSms.size());
   }
}
Run Code Online (Sandbox Code Playgroud)

我是仪器化测试的新手.这是正确的方法吗?

或者我错过了什么?

testing permissions android android-studio android-instrumentation

10
推荐指数
2
解决办法
2712
查看次数

为什么Kotlin不进行自动型铸造?

var a : Double
a = Math.sin(10) // error: the integer literal does not conform to the expected type Double
a = Math.sin(10.0) //This compiles successfully
println(a)
Run Code Online (Sandbox Code Playgroud)

为什么kotlin不执行隐式类型转换并迫使我们传递确切类型的数据?

fun sin(value: Double): Double // at kotlin documentation
Run Code Online (Sandbox Code Playgroud)

casting kotlin

5
推荐指数
1
解决办法
2124
查看次数

为什么不调用 onConfigurationChanged?

我正在编写一个代码,在更改方向时更改 TextView 的文本我正在使用 onConfigurationChanged() 侦听器来更改文本

override fun onConfigurationChanged(newConfig: Configuration?) {
    super.onConfigurationChanged(newConfig)

    val orientation : Int = getResources().getConfiguration().orientation
    val oTag = "Orientation Change"

    if(orientation == (Configuration.ORIENTATION_LANDSCAPE)){
        mytext?.setText("Changed to Landscape")
        Log.i(oTag, "Orientation Changed to Landscape")

    }else if (orientation == (Configuration.ORIENTATION_PORTRAIT)){
        mytext?.setText("Changed to Portratit")
        Log.i(oTag, "Orientation Changed to Portratit")
    }else{
        Log.i(oTag, "Nothing is coming!!")
    }
}
Run Code Online (Sandbox Code Playgroud)

但即使在日志中也没有任何反应

我也在清单文件中将此属性添加到我的活动中

android:configChanges="orientation"
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?还有其他方法可以实现这一目标吗?

android orientation onconfigurationchanged kotlin

3
推荐指数
1
解决办法
3520
查看次数

如何设置 TextInput 的宽度以匹配父级,而 alignItems='center' 为父级?

我在一个视图中有一个 TextInput,它有 alignItems='center'。通过此设置,TextInput 将采用 TextInput 中文本类型的长度。

    <View style={{
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center'
    }} >
        <TextInput />
        <Text>This is React Native</Text>
    </View>
Run Code Online (Sandbox Code Playgroud)

截图如下

在此处输入图片说明 在此处输入图片说明

而我想要实现的是将子项对齐在中心并拉伸 TextInput 的宽度以匹配父项

像这张图片

在此处输入图片说明

我如何在 react native 中实现这一点?

alignment flexbox react-native

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

如何安装react-native-vector-icons?

我真的尝试了所有可以找到的资源

关于堆栈的这个,这个以及许多其他问题在这里溢出但是我无法让它工作

我第一次使用了

react-native init myapp
Run Code Online (Sandbox Code Playgroud)

命令启动项目并按照其github页面上的说明安装react-native-vector-icons

我已经像这样导入了FontAwesome系列

import Icon from 'react-native-vector-icons/FontAwesome';
Run Code Online (Sandbox Code Playgroud)

但是,当我运行应用程序时,我在android和ios上都会出现此错误

在Android上

The development server returned response error code: 500

URL: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false

Body:
{"type":"InternalError","errors":[],"message":"Metro Bundler has encountered an internal error, please check your terminal error output for more details"}
processBundleResult
    BundleDownloader.java:242
access$100
    BundleDownloader.java:41
onResponse
    BundleDownloader.java:208
execute
    RealCall.java:135
run
    NamedRunnable.java:32
runWorker
    ThreadPoolExecutor.java:1112
run
    ThreadPoolExecutor.java:587
run
    Thread.java:818
Run Code Online (Sandbox Code Playgroud)

在iOS上

Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(Metro Bundler has encountered an internal error, please check your terminal error output …
Run Code Online (Sandbox Code Playgroud)

react-native

0
推荐指数
1
解决办法
2144
查看次数