我正在尝试按照Google Codelabs 中的示例使用 CameraX 创建自定义相机应用程序。
该教程特别指出:
We recommend using an AVD that is based on Android 11 or higher.
Run Code Online (Sandbox Code Playgroud)
它可以正常工作,API 29 (Android 10)但不能正常工作API 30 (Android 10+)并产生以下错误:
2020-08-11 11:22:34.979 8607-8698/com.codelabs.camerax E/CameraCaptureSession: Session 0: Exception while stopping repeating:
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): cancelRequest:459: Camera 0: Error clearing streaming request: Function not implemented (-38)
at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:1009)
at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:99)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1263)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:578)
at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:789)
at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:245)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:110)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:230)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923) …Run Code Online (Sandbox Code Playgroud) 从 Android 11 开始,应用可见性发生了变化。在我的应用程序中,我需要导航到邮件应用程序和导航应用程序。
需要在清单中添加以下代码
<manifest package="com.example.game">
<queries>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/jpeg" />
</intent>
</queries>
...
</manifest>
Run Code Online (Sandbox Code Playgroud)
根据文档,上面的示例允许您的应用程序查看已安装的支持 JPEG 图像共享的应用程序:
https://developer.android.com/training/basics/intents/package-visibility#intent-signature
谁能帮助我导航应用程序(谷歌导航,uber)和邮件应用程序(如outllok,gmail)需要使用什么“操作”和“数据”?
提前致谢!
我得到一个 takePictureIntent ,它不为空,但它不会将其发送到网络视图。有人有想法吗?它确实适用于旧版本 9 及以下版本,但不适用于 Android 版本 10 和 11。
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
Log.d("test", "Test1");
} catch (IOException ex) {
// Error occurred while creating the File
Toast.makeText(getApplicationContext(), "\"Unable to create Image File", Toast.LENGTH_SHORT).show();
}
// Continue only if the File was successfully created
if (photoFile != null) {
mCameraPhotoPath = "file:" + …Run Code Online (Sandbox Code Playgroud) 我有一台 android 版本 10 的设备。
另外,我有一个带有 API 22 的模拟器
这是我的 build.gradle(:app) 文件的一部分:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
dataBinding {
enabled = true
}
compileSdkVersion 'android-R'
defaultConfig {
applicationId "com.example.android.sOnline"
minSdkVersion 17
targetSdkVersion 'R'
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
// android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
}
}
Run Code Online (Sandbox Code Playgroud)
它只是不适用于“android-R”
感谢你们对我的帮助 :)
我的应用程序加载位于getFilesDir()via下的本地 html 文件WebView#loadUrl()。
之前targetSdkVersion = 29,下面的代码正在运行。
copyAssetsFile(this, "sample.html", getFilesDir().getAbsolutePath());
webView.getSettings().setJavaScriptEnabled(true);
String url = "file://" + getFilesDir().getAbsolutePath() + "/sample.html";
webView.loadUrl(url);
}
private static void copyAssetsFile(Context context, String fileName, String directoryPath) {
try {
InputStream inputStream = context.getResources().getAssets().open(fileName);
FileOutputStream fileOutputStream = new FileOutputStream(
new File(directoryPath, fileName), false);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = inputStream.read(buffer)) >= 0) {
fileOutputStream.write(buffer, 0, length);
}
fileOutputStream.close();
inputStream.close();
Run Code Online (Sandbox Code Playgroud)
完整示例在这里。
但是,它在更改后不起作用targetSdkVersion = 30 …
我的应用开始在 Android 11 设备上崩溃,并显示以下错误消息“您应用的 AndroidManifest.xml 中的元数据标记没有正确的值。预期为 12451000,但发现为 4323000”。我知道这些问题,并且我已经在清单文件中定义了正确的值,如下所示:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Run Code Online (Sandbox Code Playgroud)
如果我按照 google_play_services_version 我可以找到预期值
<integer name="google_play_services_version">12451000</integer>
Run Code Online (Sandbox Code Playgroud)
在 firebase 分析的帮助下,我可以确认它仅在 Android 11 设备上发生。

到目前为止,从各种 SO 帖子中,我尝试了以下内容:
1- 将所有使用的播放服务和 Firebase 依赖项更新到最新的可用版本。
2- 使用的工具:替换为 build clean 过程,在元数据标签中,对于 app 模块和磨损模块,如下所示:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"
tools:replace="android:value" />
Run Code Online (Sandbox Code Playgroud)
3- 检查@integer/google_play_services_version 中所有使用的第 3 部分库/SDK 的清单文件,但所有文件都重定向到预期值,即 12451000。
以下是 build.gradle 文件: A- build.gradle {:app}-
apply from: '../release-config.gradle'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'android-release-plugin'
apply plugin: 'testfairy'
apply from: …Run Code Online (Sandbox Code Playgroud) android gradle android-manifest google-play-services android-11
在 Android 11 SDK 30 中,在每个活动开始时我都会得到如下堆栈跟踪:
2020-12-30 10:08:00.175 1417-1436/? D/EventSequenceValidator: IntentStarted during UNKNOWN. Intent { cmp=com.lampreynetworks.ahd.health.at.home/.DebugLogActivity }
java.lang.Throwable: EventSequenceValidator#getStackTrace
at com.google.android.startop.iorap.EventSequenceValidator.logWarningWithStackTrace(EventSequenceValidator.java:260)
at com.google.android.startop.iorap.EventSequenceValidator.onIntentStarted(EventSequenceValidator.java:106)
at com.android.server.wm.LaunchObserverRegistryImpl.handleOnIntentStarted(LaunchObserverRegistryImpl.java:139)
at com.android.server.wm.LaunchObserverRegistryImpl.lambda$veRn_GhgLZLlOHOJ0ZYT6KcfYqo(Unknown Source:0)
at com.android.server.wm.-$$Lambda$LaunchObserverRegistryImpl$veRn_GhgLZLlOHOJ0ZYT6KcfYqo.accept(Unknown Source:10)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:292)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:201)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:44)
Run Code Online (Sandbox Code Playgroud)
所有活动都有效,如果我不查看 Logcat,我永远不会知道。然而,我不明白它,它一定是某种问题的迹象,(最终)会回来咬我。有人了解这种行为并知道如何解决它吗?
从 4.0.3 开始,我就已经在许多版本中使用过这段代码,但直到现在才见过它。请注意,每个活动都会发生这种情况。
我遇到的所有隐藏 Android 应用状态栏的方法在 Android 11 中均已弃用。
有谁知道目前可以接受的方法吗?
我还使用 Kotlin 来开发我的应用程序。
android kotlin android-statusbar android-api-levels android-11
由于某种原因,我真的很挣扎,希望有人能帮助我指明正确的方向。
我的目标是 Android 11 / API 30,这似乎是所有问题的根源。降低目标可能对我有用——但谷歌似乎最终会迫使我走上这条路,所以我不妨弄清楚这一点。
我的应用程序通常会按照标准写入文件
getExternalFilesDir(null)
Run Code Online (Sandbox Code Playgroud)
这给了我设备上的一条路径
/storage/emulated/0/Android/data/com.domain.testapp/files
Run Code Online (Sandbox Code Playgroud)
我还尝试了其他类型,例如:
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
Run Code Online (Sandbox Code Playgroud)
结果是
/storage/emulated/0/Android/data/com.domain.testapp/files/Documents
Run Code Online (Sandbox Code Playgroud)
我的应用程序实际上将文件写入此位置没有任何问题。在 Android 11 中,我必须使用本地文件浏览器跳过一些麻烦才能查看这些文件 - 但它们确实存在于设备上。
我现在试图为用户提供一些查看文件和共享文件的能力,这就是我所困惑的地方!
下面的代码导致找不到文件
File filePath = this.getExternalFilesDir(null);
String filePathString = filePath.toString();
ArrayList<String> myData = new ArrayList<>();
File fileDir = new File(filePathString);
String[] files = fileDir.list();
if(files.length == 0){
Log.w(APPID, "NO FILES IN FOLDER");
}
Run Code Online (Sandbox Code Playgroud)
是的 - 我知道不需要 File 和 .toString() - 但我每一步都将它们注销,因为我认为我疯了。
我知道这个应用程序指向的文件夹中有十几个左右的文件。该应用程序创建了文件。不是应该能看到文件夹里的文件吗???
Manifest 具有以下权限 - 我认为它不需要全部:
<uses-permission android:name = "android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)
没有权限显示为应用程序被拒绝
我想过使用外部存储 - 但似乎这在 Android …
设想
我有两个应用程序,一个是跟踪器应用程序,它记录传入和传出呼叫并压缩这些文件,并将文件路径发送到主应用程序,通过主应用程序将Inter-Process Communication这些文件上传到服务器。
现在我正在将这两个应用程序升级到 Android 11。在 Tracker 应用程序中,我用于MediaStore.Files API保存文件并尝试使用主应用程序中的文件路径读取这些文件。读取文件时File.canRead()返回false主应用程序。即使我尝试MediaStore API读取这些文件,它也会返回空Cursor。
在这里我有几个问题。
MANAGE_EXTERNAL_STORAGE访问存储中的所有文件?我正在将文件保存在 public 目录中Documents/AppData/Audio。请给我有关此的工作链接。任何帮助将不胜感激。谢谢
android mediastore storage-access-framework scoped-storage android-11