我想在我的Android应用程序中加入一个PlusOneButton.我按照google(https://developers.google.com/+/mobile/android/getting-started?hl=en)所述,在我的debug.keystore中使用SHA-1在google云控制台上创建了应用程序.
在我的XML-Layout中,我添加了+ 1-Button:
<com.google.android.gms.plus.PlusOneButton
android:id="@+id/btnPlusOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
plus:size="standard" />
Run Code Online (Sandbox Code Playgroud)
在我的Activity中,我重写了onResume()方法.当然我首先通过findViewById(...)检索对象:
public void onResume() {
super.onResume();
btnPlusOne.initialize("http://www.google.de", REQUEST_CODE_PLUS_ONE);
}
Run Code Online (Sandbox Code Playgroud)
我还在Manifest中给出了权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
Run Code Online (Sandbox Code Playgroud)
但是,如果我启动我的应用程序,PlusOneButton看起来是灰色的.如果我单击它,按钮中会出现一个进度条并无限运行.在Logcat上我收到此消息:
18367-18367/? W/PlusOneButtonView? Failed to establish connection with status: 8
Run Code Online (Sandbox Code Playgroud)
如果我在API-Doc(http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html#INTERNAL_ERROR)中查看此内容,则说明内部错误.但目前我不知道什么可以解决这个问题?
我必须与以下四个RESTServices进行通信.
Germany (Default): http://url.com/suggest?query=
Austria http://url.com:82/suggest?query=
Swiss: http://url.com:83/suggest?query=
Spain: http://url.com:84/suggest?query=
Run Code Online (Sandbox Code Playgroud)
基本上我必须在每个国家/地区的不同TCP端口上调用相同的RESTService.当我创建一个Retrofit-RestAdapter时,我必须提供一个端点(base-url):
RestAdapter.Builder builder = new RestAdapter.Builder();
ObjectMapper mapper = new ObjectMapper();
builder.setEndpoint("http://url.com");
Run Code Online (Sandbox Code Playgroud)
如果我想访问上面提到的那四个RESTServices,我是否必须为它们中的每一个创建一个RestAdapter?或者是否可以只使用一个RestAdapter实例?
我尝试通过添加TCP-Port作为RestInterface-annotation的一部分来解决问题,但这不起作用:
public interface AutoSuggestRemote {
@GET (":{port}/suggest")
public Response getSuggestions(@Path ("port") Integer httpPort, @Query ("query") String query);
}
Run Code Online (Sandbox Code Playgroud)
我在Logcat中得到以下异常:
java.lang.IllegalArgumentException: AutoSuggestRemote.getSuggestions: URL path ":{port}/suggest" must start with '/'.
at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:123)
at retrofit.RestMethodInfo.parsePath(RestMethodInfo.java:212)
at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:165)
at retrofit.RestMethodInfo.init(RestMethodInfo.java:133)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at $Proxy3.getSuggestions(Native Method)
Run Code Online (Sandbox Code Playgroud)
因此我的问题是,如果我必须为每个RESTService创建一个RestAdapter实例,或者是否有办法通过使用相同的RestAdapter实例与所有四个服务进行通信.
我正在使用带有此代码的android本机共享:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "I like to share with you some stuff.");
intent.putExtra(Intent.EXTRA_SUBJECT, "I like to share with you.");
intent.setType(CONTENT_TYPE_TEXT);
startActivity(Intent.createChooser(intent, "Share");
Run Code Online (Sandbox Code Playgroud)
当我使用电子邮件作为分享渠道时,我得到了我想要的:
Subject: I like to share with you.
Text: I like to share with you some stuff.
Run Code Online (Sandbox Code Playgroud)
当我使用 WhatsApp 作为分享渠道时,我得到以下文本:
I like to share with you.
I like to share with you some stuff.
Run Code Online (Sandbox Code Playgroud)
与 Whatsapp 分享时我期望什么:
I like to share with you some stuff.
Run Code Online (Sandbox Code Playgroud)
如果共享频道基本上不支持主题,是否有任何选项/标志指示共享频道来抑制主题。
例如,电子邮件支持主题 -> 使用额外提供的意图。WhatsApp 不支持主题 -> 不要额外使用提供的意图。
我正在使用React Native共享方法(https://facebook.github.io/react-native/docs/share.html)在Android上共享内容。
根据文档,我们可以通过以下方式使用它:
Share.share({
message: 'React Native | A framework for building native apps using React'
})
.then((result) => {
console.log(result.action) // returns sharedAction
})
.catch((error) => {
console.log(error)
})
Run Code Online (Sandbox Code Playgroud)
因此,当我们调用Sharemethod时,我们将得到结果,then然后会出现一个弹出窗口,其中包含可共享消息内容的应用列表。
问题:
弹出窗口还包含一个cancel按钮,因此当用户单击它时,窗口会关闭,但是在文档中没有可用/提及的捕获它的方法。
有什么方法可以捕获取消事件,因为我想在用户单击它时执行一些操作。
感谢在广告中。:)
我在我的项目中包含了 detekt ( https://github.com/arturbosch/detekt/ ):
根构建.gradle
buildscript {
ext.kotlin_version = '1.3.50'
ext.detekt_version = "1.0.1"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version"
}
}
plugins {
id("io.gitlab.arturbosch.detekt").version("1.0.1")
}
Run Code Online (Sandbox Code Playgroud)
应用程序构建.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.gitlab.arturbosch.detekt'
Run Code Online (Sandbox Code Playgroud)
android { // .. 只是默认值 }
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// ... other dependencies
detekt "io.gitlab.arturbosch.detekt:detekt-formatting:$detekt_version"
detekt("io.gitlab.arturbosch.detekt:detekt-cli:$detekt_version")
}
detekt {
toolVersion = "$detekt_version"
input = files("src/main/java") …Run Code Online (Sandbox Code Playgroud) 我要在第一个Flutter应用中单击一个按钮后,对OpenWeatherMap-API进行网络请求(Rest API)。基本上,我正在按照本教程进行操作:从Internet上获取数据
因此,我创建了API调用,该调用紧随本教程之后,并且像一个咒语一样工作:
class OpenWeatherApi {
static const _API_KEY = "asdbaklsadfkasdlfkasdjfl";
Future<CurrentWeather> getCurrentWeather(String location) async {
final url =
"https://api.openweathermap.org/data/2.5/weather?q=$location&APPID=$_API_KEY";
final response = await get(url);
final responseJson = json.decode(response.body);
return new CurrentWeather.fromJson(responseJson);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在有状态窗口小部件中调用API:
class _MyHomePageState extends State<MyHomePage> {
String _currentWeather = "";
void _callWeatherApi() {
var api = new OpenWeatherApi();
api.getCurrentWeather("Waldershof, Germany").then((weather) {
setState(() {
_currentWeather = weather.getTextualRepresentation();
});
}, onError: (error) {
setState(() {
_currentWeather = error.toString();
});
});
}
@override
Widget build(BuildContext context) {
return …Run Code Online (Sandbox Code Playgroud) 我用Android Studio Preview 3.0(Canary 2)创建了一个项目来开始Kotlin开发.我使用Android Studio Fabric插件为我的项目设置Fabric.
但是,当我想使用以下命令将我的应用程序的测试版上传到Fabric Beta(Crashlytics)时
./gradlew crashlyticsUploadDistributionDebug
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
项目':app'中的配置'compile'已弃用.请改用"实施".项目':app'中的配置'testCompile'已弃用.请改用"testImplementation".不推荐使用Task.leftShift(Closure)方法,并计划在Gradle 5.0中删除它.请改用Task.doLast(Action).不推荐使用registerResGeneratingTask,不推荐使用registerGeneratedFolders(FileCollection)registerResGeneratingTask,使用registerGeneratedFolders(FileCollection):app:crashlyticsUploadDistributionDebug FAILED
FAILURE:构建因异常而失败.
出了什么问题:任务执行失败':app:crashlyticsUploadDistributionDebug'.
无效.
尝试:使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行以获取更多日志输出.
在1s 1可操作的任务中建立失败:1执行,0避免(0%)
我不知道,什么"无效"的意思.
这是我的根build.gradle:
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
maven { url 'https://maven.google.com' }
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.ajoberstar:grgit:1.9.0'
classpath 'io.fabric.tools:gradle:1.22.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
supportLibVersion = "25.3.1"
buildVersion …Run Code Online (Sandbox Code Playgroud) 我更新了我的build.gradle以使用android-gradle插件1.2.2(而不是1.1.0):
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试同步我的项目,我会得到一个例外.我的build.gradle
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'LICENSE.txt'
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.kupferwerk.myapplication"
minSdkVersion 15
targetSdkVersion 22
versionCode 100
versionName "1.0.0"
}
lintOptions {
abortOnError false
disable 'ContentDescription'
disable 'InvalidPackage'
}
buildTypes {
release {
minifyEnabled false
proguardFiles 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
testCoverageEnabled true
}
}
}
project.gradle.taskGraph.whenReady {
connectedAndroidTest {
ignoreFailures = true
}
}
Run Code Online (Sandbox Code Playgroud)
错误是
Error:(58) No such property: ignoreFailures for class: org.gradle.api.DefaultTask_Decorated
Run Code Online (Sandbox Code Playgroud)
在我的build.gradle文件的这一部分内: …
我有一个PublishSubject注册doOnSubscribe和doOnUnsubscribe操作.如果订阅完成,则不会调用这两个操作.
private PublishSubject<Long> publishSubject;
private Subscription subscription;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
publishSubject = PublishSubject.create();
publishSubject.doOnSubscribe(new Action0() {
@Override
public void call() {
Log.d("SUBJECT", "Someone subscribed.");
}
});
publishSubject.doOnUnsubscribe(new Action0() {
@Override
public void call() {
Log.d("SUBJECT", "Someone UNsubscribed.");
}
});
Observable.interval(1, TimeUnit.SECONDS).subscribe(new Action1<Long>() {
@Override
public void call(final Long tick) {
publishSubject.onNext(tick);
}
});
}
@Override
protected void onResume() {
super.onResume();
subscription = publishSubject.subscribe(new Action1<Long>() {
@Override
public void call(final Long aLong) …Run Code Online (Sandbox Code Playgroud) 我有 Observable,当某些数据来自 BLE 连接时,它会发出项目:
public interface CommunicationController {
Flowable<DataContainer> dataReceived();
}
Run Code Online (Sandbox Code Playgroud)
除此之外,我想构建一个Observable,completes当满足以下条件之一时:
A。我收到两条特定类型的消息(这是通过filter在收到的DataContainer项目上使用运算符来完成的。
communicationController.dataReceived()
.filter(data -> isTypeA(data) || isTypeB(data))
.take(2)
.toList()
.map(dataContainers -> doSomeMappingToCommon object)
Run Code Online (Sandbox Code Playgroud)
b. 我收到一条特定类型的消息(再次使用filter运算符)。
communicationController.dataReceived()
.filter(data -> isTypeC(data))
.firstOrError()
.map(dataContainers -> doSomeMappingToCommon object);
Run Code Online (Sandbox Code Playgroud)
我怎样才能将这两个合并Observable为一个?此外,两个 Observable 中只有一个会发出一个项目。
我已经按照此处的定义在我的项目上设置了 Flutter 集成测试:https : //flutter.dev/docs/testing/integration-tests
我使用了以下 devDepencendies:
integration_test: ^1.0.0
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
Run Code Online (Sandbox Code Playgroud)
测试驱动程序只是来自项目页面的 C&P:
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() => integrationDriver();
Run Code Online (Sandbox Code Playgroud)
最终测试:
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('CPCSA-TC-016: Vehicle Card with no alert',
(WidgetTester tester) async {
app.main();
// Execute test code.
});
}
Run Code Online (Sandbox Code Playgroud)
最后我运行我的测试
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/test.dart
这基本上没问题,但它在每次执行时都会编译,这非常耗时。我是否有机会运行集成测试并拥有与常规开发相同的热重载功能?如何实现这一目标?
或者还有其他解决方法吗?我正在考虑首先将测试代码编写为单元/小部件测试,然后在执行正确后将其移植到集成测试中。
integration-testing flutter hot-reload flutterdriver flutter-integration-test
所以我是android编程的新手。我正在尝试学习它,以便可以在大学项目中工作,该项目是在线食品订购应用程序。因此,作为新手,我指的是此视频教程-https ://www.youtube.com/watch?v= Ad41Bh704ms&list = PLaoF-xhnnrRW4lXuIhNLhgVuYkIlF852V
上传者使用的是Android Studio版本2.3.3,而我使用的是Android Studio 3.3.1。因此,我知道这里和那里的更改很少。现在,我被困在那版毕加索的变化中。
我已经使用了准确的代码组作为他,但是对我来说,它在“加载”时出错,请在 此处输入图片描述
这就是它的意思- 在此处输入图片描述
我已经在build.gradle中将此版本的毕加索添加为依赖项。 在这里输入图像描述 有人可以在这里帮助我吗?什么可能会触发“加载”中的错误,我该如何解决?提前致谢
android ×10
flutter ×2
gradle ×2
crashlytics ×1
dart ×1
detekt ×1
email ×1
google-plus ×1
hot-reload ×1
kotlin ×1
picasso ×1
port ×1
react-native ×1
react-redux ×1
react-router ×1
rest ×1
retrofit ×1
rx-android ×1
rx-java ×1
rx-java2 ×1
whatsapp ×1