Android 13 的行为更改提到了这一点:
如果您的应用面向 Android 13,则必须请求一项或多项新权限,而不是 READ_EXTERNAL_STORAGE 和 WRITE_EXTERNAL_STORAGE 权限。
(https://developer.android.com/about/versions/13/behavior-changes-13#capsular-media-permissions)
新的权限是:
但是,如果我需要从任意文件夹读取 PDF 文件,该如何处理?没有像 READ_MEDIA_DOCUMENT 之类的权限。那么除图像、视频或音频之外的其他文件类型呢?我仍然可以对它们使用 READ_EXTERNAL_STORAGE 权限吗?
我在官方文档中没有找到有关此内容的任何信息,但说实话,该文档仅关注媒体文件,没有任何有关其他文件类型的信息(https://developer.android.com/about/versions/13/行为更改13#细粒度媒体权限)。
我也不确定除视频、图像和音频之外的其他文档类型的 WRITE_EXTERNAL_STORAGE 权限。
我有两个挂起功能:
suspend fun sendData() : Boolean
suspend fun awaitAcknowledge() : Boolean
Run Code Online (Sandbox Code Playgroud)
我想将它们包装在第三个挂起函数中,它们应该在其中并行执行,并且我想通过具有两个返回值来计算最终结果:
suspend fun sendDataAndAwaitAcknowledge() : Boolean {
// TODO execute both in parallel and compare both results
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我这样写的话,
suspend fun sendDataAndAwaitAcknowledge() : Boolean {
val sendResult = sendData()
val receiveAck = awaitAcknowledge()
}
Run Code Online (Sandbox Code Playgroud)
这些函数将按串行顺序执行,这在我的情况下不起作用。
来自 RxJava,我想实现类似zip
操作符的功能:
Single.zip(awaitAcknowledge(), sendData(), {receiveAck, sendResult -> ...})
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点Coroutines
?
我创建了一个带有class属性的Kotlin类,我想在构造函数中初始化它:
public class TestClass {
private var context : Context? = null // Nullable attribute
public constructor(context : Context) {
this.context = context
}
public fun doSomeVoodoo() {
val text : String = context!!.getString(R.string.abc_action_bar_home_description)
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我必须使用"?"将属性声明为Nullable.符号,虽然该属性将在构造函数中初始化.将此属性声明为Nullable属性使得始终需要强制使用"!!"的NonNull值 或者用"?"提供空检查.
有没有办法避免这种情况,如果class属性将在构造函数中初始化?我想欣赏像这样的解决方案:
public class TestClass {
private var context : Context // Non-Nullable attribute
public constructor(context : Context) {
this.context = context
}
public fun doSomeVoodoo() {
val text : String = context.getString(R.string.abc_action_bar_home_description)
}
}
Run Code Online (Sandbox Code Playgroud) 我想在我的AppTheme中设置一个默认的textcolor,它应该是黑色的(不是默认的Material Design深灰色).应该通过在UI元素(例如TextView)上通过android:textAppearance-attribute设置自定义样式来覆盖textColor.
这是我目前的设置:
我在我的项目中使用AppCompat-Library:
compile 'com.android.support:appcompat-v7:22.2.0'
Run Code Online (Sandbox Code Playgroud)
我定义了以下主题:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/black</item> <!-- All TextViews should have this color as default text color -->
</style>
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml中设置:
<application
android:name=".core.BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)
此外,我定义了一些样式来改变一些TextViews的textAppearance:
<style name="App.Heading" parent="android:TextAppearance.Widget.TextView">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/red</item>
</style>
<style name="App.Heading.Highlighted" parent="android:TextAppearance.Widget.TextView">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/blue</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在我有一些带有一些TextView的xml布局.其中一些应该具有默认的textAppearance(实际上是在我的主题中定义为android:textColorPrimary的黑色文本颜色).有些应该应用我定义的样式的自定义textappearance:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="CUSTOM: App.Heading"
android:textAppearance="@style/App.Heading" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="CUSTOM: App.Heading.Highlighted"
android:textAppearance="@style/App.Heading.Highlighted" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Normal Textview with no …
Run Code Online (Sandbox Code Playgroud) 我Service
在Android O上运行后台时遇到了一种奇怪的行为.
我的示例应用使用了 targetSdkVersion 26
我有一个简单的服务,只打印出一些状态信息,并使用START_STICKY
以下方式重新创建:
class ServiceTest : Service() {
companion object {
private val TAG = "ServiceTest"
fun buildIntent(context: Context): Intent {
return Intent(context, ServiceTest::class.java)
}
}
override fun onBind(p0: Intent?): IBinder? {
return null
}
override fun onCreate() {
super.onCreate()
Log.d(TAG, "onCreate")
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d(TAG, "onStartCommand: startId = " + startId)
return START_STICKY
}
override fun onDestroy() {
Log.d(TAG, "onDestroy")
super.onDestroy()
}
}
Run Code Online (Sandbox Code Playgroud)
该服务在活动中启动: …
在我们的build.gradle中,我们将播放服务广告库从6.5.87更新为7.5.0
compile com.google.android.gms:play-services-ads:7.5.0
Run Code Online (Sandbox Code Playgroud)
升级后,我们在合并的AndroidManifest.xml中看到了一个新权限(放在/ build/intermediates/manifests/full/release /中)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)
关于ManifestMerger的日志,play-services-ads添加了此权限:
ADDED from com.google.android.gms:play-services-ads:7.5.0:30:9
android:theme
ADDED from com.google.android.gms:play-services-ads:7.5.0:31:13
android:name
ADDED from com.google.android.gms:play-services-ads:7.5.0:30:19
uses-permission#android.permission.WRITE_EXTERNAL_STORAGE
Run Code Online (Sandbox Code Playgroud)
在官方文档中,我们没有看到任何需要此权限的提示.仅记录以下权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Run Code Online (Sandbox Code Playgroud)
有没有官方信息,为什么添加这个新的权限?或者这是一个错误?
目前我们无法解释我们的用户,为什么我们需要这个新的权限.
编辑:错误的警报! 我误解了manifest-merger-result.txt.play-services- ads依赖项未添加新权限,但我们还添加了play-services- location依赖项.play-services- location引用了play-services- maps,这需要这个权限来缓存tile.
manifest-merger-result.txt的正确解释是:
uses-permission#android.permission.WRITE_EXTERNAL_STORAGE
ADDED from com.google.android.gms:play-services-maps:7.5.0:22:5
Run Code Online (Sandbox Code Playgroud)
如果添加了lib,则play-services-maps会自动添加此"缺失"权限.如果我们不使用Map-API,如果删除这个map-permissions是个好主意,那将是很好的.因为我们只使用Location-API.
我安装了MacOS 10.11 El Capitain.今天我收到了Intel HAXM 6.0.4可用的通知,Android SDK Manager建议我删除Intel HAXM 6.0.3.我做的.
但现在,我得到的消息是Intel HAXM 6.0.4与MacOS不兼容.
有没有办法让旧版本6.0.3回来?或者有其他选择吗?
我正在开发一个Android应用程序,它将监听语音命令并相应地触发操作.
以下是一些疑问:
我们可以用唤醒词创建我们自己的单词和命令词典.
应用程序应该在脱机模式下工作(没有Internet).
我想在我的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)中查看此内容,则说明内部错误.但目前我不知道什么可以解决这个问题?
我有以下Observable,它将每30秒执行一次带有Retrofit的REST调用:
Subscription subscription = Observable.interval(0, REFRESH_INTERVAL, TimeUnit.SECONDS)
.concatMap(new Func1<Long, Observable<Response>>() {
@Override
public Observable<Response> call(Long time) {
return webservice.callRetrofitServiceWithRx(parameter);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new UpdateSuccessAction(), new UpdateErrorAction());
Run Code Online (Sandbox Code Playgroud)
可能会发生(特别是REST-Call)抛出异常(例如没有互联网连接).
我想要实现的目标:
Observable应该发出/暴露异常,以便我可以在UI上显示错误消息,但它应该继续发出项目(在30秒内重试).
目前研究
如果我没有定义任何特殊行为,Observable会发出异常并停止工作(=在30秒内不重试).
如果我尝试重试操作符,异常将被吞下并且不会被暴露,因此我无法在ui中显示错误.
如果我尝试onErrorReturn运算符,我可以处理异常,但据我所知,不能重试.
解决方法
我目前的解决方法是重新订阅此Observable,但我想知道某人是否有更优雅的解决方案.
android ×9
kotlin ×2
admob ×1
android-13 ×1
constructor ×1
google-plus ×1
haxm ×1
macos ×1
offline ×1
rx-android ×1
rx-java ×1
textview ×1