小编Kab*_*bir的帖子

集成测试的颤振位置权限不起作用

我正在尝试为我的位置应用程序编写内容integration_test。我需要允许我的integration_test 的位置权限。

我已经ANDROID_SDK_ROOT在我的windows环境变量中设置了。我已经从命令提示符和 Android Studio 终端进行了测试,两者都显示良好。https://i.ibb.co/4gDPs3Z/echo-android-sdk-root.jpg

不幸的是,我 ANDROID_SDK_ROOTnull. Platform.environment我已附上屏幕截图https://i.ibb.co/t2Y3fBc/android-sdk-root-not-found.jpg

如果我硬编码envVars到我的 Windows 机器的 Android 位置C:/Users/User/AppData/Local/Android/Sdk/platform-tools/adb.exe,那么它会抛出错误

No such file or directory Command: C:/Users/User/AppData/Local/Android/Sdk/platform-tools/adb.exe shell pm grant com.dealerapp.mlink android.permission.ACCESS_COARSE_LOCATION

下面是我的源代码

Future<void> grantLocationPermission() async{

    final Map<String, String> envVars = Platform.environment;
    print('evnVars = $envVars');
    print('ANDROID_SDK_ROOT = ${envVars['ANDROID_SDK_ROOT']}');
    final String adbPath = envVars['ANDROID_SDK_ROOT']! + '/platform-tools/adb.exe';
    
    await Process.run(adbPath, [
      'shell',
      'pm',
      'grant',
      'com.abcd.efgh', //my app package
      'android.permission.ACCESS_COARSE_LOCATION'
    ]);
    await Process.run(adbPath, [
      'shell',
      'pm', …
Run Code Online (Sandbox Code Playgroud)

android integration-testing android-permissions flutter

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

android 服务需要在一段时间后停止

我正在运行一个Service使用AlarmManager. 运行Service正常,我正在Service手动停止(单击 a Button),但我需要在一段时间后停止Service(可能是 10 秒)。我可以使用,但 在给定时间后this.stopSelf();如何调用?this.stopSelf();

service android

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

引起:java.lang.IllegalArgumentException:provider = network

试图找到我的device.code的当前位置在这里.

package com.example.location;

import android.app.Activity;    
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;


public class LocationActivity extends Activity
{

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  /* Use the LocationManager class to obtain GPS locations */
  LocationManager mlocManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

  LocationListener mlocListener = new MyLocationListener();
  mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
}

/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{

  @Override
  public void …
Run Code Online (Sandbox Code Playgroud)

android

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

睡眠功能不起作用

我希望在可更改的文本中显示1到100.我喜欢使用sleep()函数,因此看起来它正在将表单1增加到100.我的代码是

for(int i= 0;i<100;i++) {
    scorelevel.setText(String.valueOf(i));
    try{
        Thread.sleep(1000);
    }catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

但它没有正确显示.任何帮助或建议表示赞赏.

android andengine

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