随着 android N 最近的变化,我不得不升级我的代码以使用 FileProvider 使用相机/文件管理器获取图像/文件。该代码在模拟器(genymotion)中运行良好,但在 Moto G4 plus 中抛出 IO 异常。
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
try {
ParcelFileDescriptor fcd = getContentResolver().openFileDescriptor(uriOrig,"r");// uriOrig is the uri returned from camera
if(fcd != null) {
InputStream inputStream = new FileInputStream(fcd.getFileDescriptor());
uploadCall =RestService.getInstance().uploadFile(mimeType, name, size,
inputStream, defaultResponseCallback);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
这里是上传文件的方法。
public Call<Attachment> uploadFile(final String mimeType, final String name, final long length,final InputStream is, final Callback<Attachment> callback) {
final int byteCount = 8192;
if (length > 0) { …Run Code Online (Sandbox Code Playgroud) 这是我的build.gradle(app)
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.my.app"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
}
ant.importBuild 'assets.xml'
preBuild.dependsOn(list, …Run Code Online (Sandbox Code Playgroud) 要在约束布局中为一组视图设置背景,想法是创建一个视图项并将其约束到极端视图的边界。但是如果一个组仅依赖于右侧约束,则无法向左侧添加边距,因此可能设置背景的视图组没有左填充,
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View"/>
<variable
name="audio"
type="example.model.observables.AttachmentObservableModel"/>
</data>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/selector_chat_row"
>
<include
android:id="@+id/message_preview_layout"
layout="@layout/reply_preview_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:minWidth="160dp"
android:layout_marginLeft="10dp"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Barrier
android:id="@+id/left_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="left"
app:constraint_referenced_ids="play_pause,message_preview_layout" />
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/chat_me_background"
app:layout_constraintBottom_toBottomOf="@+id/play_pause"
app:layout_constraintLeft_toLeftOf="@+id/left_barrier"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="@null"
android:enabled="@{!(audio.filePath == null || audio.filePath.isEmpty())}"
android:onClick="@{() -> audio.playing? audio.onPausePressed(): audio.onPlayPressed()}"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:src="@{audio.playing? @drawable/ic_pause_circle_filled: @drawable/ic_play_arrow}"
app:layout_constraintRight_toLeftOf="@+id/seekbar"
app:layout_constraintTop_toBottomOf="@+id/message_preview_layout" />
<android.support.v7.widget.AppCompatSeekBar
android:id="@+id/seekbar"
android:layout_width="170dp" …Run Code Online (Sandbox Code Playgroud) 在Kotlin反复面对这个问题
fun test(){
compute { foo -> Log.e("kotlin issue", "solved") } // This line is //showing error
}
fun compute(body: (foo:String) -> Unit?){
body.invoke("problem solved")
}
Run Code Online (Sandbox Code Playgroud)