小编Bok*_*ken的帖子

将材料设计图标导入到android项目中

有没有一种简单的方法可以将Material Design图标存储库的所有图标导入到Android项目中而不会手动执行此操作?

icons material-design

130
推荐指数
4
解决办法
8万
查看次数

java.io.FileNotFoundException:/ storage/emulated/0/new file.txt:open failed:EACCES(Permission denied)

我一直在尝试加密文件并将这些文件重新写回到同一个地方.但是我收到了错误消息"java.io.FileNotFoundException: /storage/emulated/0/New file.txt: open failed: EACCES (Permission denied)".

我的Manifest档案是这个

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tdk.mytestapplication2">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


<application
    android:allowBackup="true"
Run Code Online (Sandbox Code Playgroud)

我想我已在那里提供了正确的许可.我用来加密文件的代码就是这个.

public static void encrypt(SecretKey secretKey, String filePath){
    try {
        // Here you read the cleartext.
        FileInputStream fis = new FileInputStream(filePath);
        // This stream write the encrypted text. This stream will be wrapped by another stream.
        FileOutputStream fos = new FileOutputStream(filePath);

        // Create cipher
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        // Wrap the output stream
        CipherOutputStream cos = …
Run Code Online (Sandbox Code Playgroud)

java android android-permissions

25
推荐指数
4
解决办法
7万
查看次数

如何修复此错误“执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障”

我无法在AVD上运行我的应用程序。我收到这个错误。

执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障

我的 build.gradle

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.myapplication"
    minSdkVersion 15
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}[E][1]}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

android android-studio

25
推荐指数
3
解决办法
9万
查看次数

Dart/Flutter 如何比较两个 TimeOfDay 时间?

TimeOfDay文档没有比较运算符,原始比较不起作用。我现在能想到的唯一解决方案是转换TimeOfDayDateTime并使用DateTime的差异方法。

有没有人有更好的解决方案?

datetime dart timeofday flutter

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

我们有任何工具可以将Android xml布局转换为.java文件吗?

我有XML格式的布局文件.但我想在我的Java代码中以编程方式创建我的视图.有没有工具可以将XML布局文件转换为等效的Java代码?

java xml android android-layout

12
推荐指数
2
解决办法
7174
查看次数

引起原因:java.lang.NoSuchMethodException:&lt;init&gt; [class android.app.Application] - viewmodel

我正在我的 Android 应用程序中创建自己的视图模型。
\n当应用程序启动时,它崩溃了,我收到了错误

\n
\n

“由以下原因引起:java.lang.NoSuchMethodException:[class android.app.Application]”

\n
\n

1.查看模型类:

\n
public class MainViewModel extends AndroidViewModel implements OnCommunicationListener {\n    \npublic MainViewModel(@NonNull Application application, DeviceData deviceData) {\n        super(application);\n\n\xe2\x80\xa6.\n}\n
Run Code Online (Sandbox Code Playgroud)\n

2.查看模型工厂

\n
public class ViewModelFactory extends ViewModelProvider.AndroidViewModelFactory {\n\n    @NonNull\n    private final Application application;\n    private final DeviceData deviceData;\n\n    public ViewModelFactory(@NonNull Application application, DeviceData deviceData) {\n        super(application);\n        this.application = application;\n        this.deviceData = deviceData;\n    }\n\n    @NonNull\n    @Override\n    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {\n        if (modelClass.isAssignableFrom(MainViewModel.class)) {\n            return (T) new MainViewModel(application, deviceData);\n …
Run Code Online (Sandbox Code Playgroud)

android android-viewmodel

12
推荐指数
2
解决办法
7809
查看次数

从 Fabric 切换到 Firebase Crashlytics 问题:缺少 Crashlytics 构建 ID

从 Fabric 切换到 Firebase Crashlytics SDK 后,我遇到了问题。问题如标题所示:缺少 Crashlytics 构建 ID。当您的应用程序的构建配置中缺少 Crashlytics 工具时,就会发生这种情况。请查看 Crashlytics 入门说明并确保您拥有有效的 Crashlytics 帐户。

我有从控制台生成的 json 文件(仔细检查这些和键,其他一切看起来没问题)。我在 gradle 中添加了库。我正在调用'throw new RuntimeException("Test Crash");' 并收到一个关于构建 ID 的错误,我不知道它是什么......

android build firebase google-fabric

12
推荐指数
3
解决办法
3557
查看次数

如何从图像Android应用程序中提取文本

我正在为我的Android应用程序开发一项功能.我想从图片中读取文本,然后将该文本保存在数据库中.使用OCR是最好的方法吗?还有另外一种方法吗?Google在其文档中建议NDK只应在严格必要时使用,但究竟是什么垮台?

任何帮助都会很棒.

图像是OCR'd

在此输入图像描述

在此输入图像描述

在此输入图像描述

ocr text tesseract image

11
推荐指数
2
解决办法
2万
查看次数

启动前台的错误通知,服务通知的无效通道:

所以,我在商店里有一个有 50000 个用户的应用程序。最近我更新了我的 android studio 并将 SDK 编译为 27。我做了一些更改以支持 android 8 更改,包括通知更改(例如通知应该有唯一的频道)。在 Android One 手机(运行 android 8)上对此进行了测试。一切都很顺利。在 Playstore 上更新应用程序后,我在 android 8 设备(主要是 Google Pixel 手机)上看到这些崩溃

Fatal Exception: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=-2 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0xffffcf00 actions=3 vis=PRIVATE)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
   at android.os.Handler.dispatchMessage(Handler.java:106)
   at android.os.Looper.loop(Looper.java:164)
   at android.app.ActivityThread.main(ActivityThread.java:6494)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Run Code Online (Sandbox Code Playgroud)

我在 Crashlytics 上看到了其中 7 个错误。每个都有相同的日志,大约 10 个用户有大约 5000 多次崩溃。因此,apprently 应用程序在循环中崩溃。

我遇到的问题是这些日志不提供任何日志,我可以从那里看到我的应用程序中启动此崩溃的源。 有什么办法可以找出哪个班级引发了这次崩溃?有什么帮助吗?

我也有这个通知代码:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { …
Run Code Online (Sandbox Code Playgroud)

service notifications android android-8.0-oreo android-8.1-oreo

10
推荐指数
3
解决办法
2万
查看次数

java.io.FileNotFoundException:打开失败:EACCES(权限被拒绝)

当我尝试将位图存储到存储中时出现此错误 #

    File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "picture");
    if (! path.exists()) {
        path.mkdirs();
        if (!path.exists()) {
            return null;
        }
    }
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HH_mm_ss", Locale.CHINA).format(new Date());
    File imagePath = new File(path.getPath() + "_" + "IMG_" + timeStamp + ".jpg");
    BufferedOutputStream fos;
    try {
        fos =new BufferedOutputStream(new FileOutputStream(imagePath));
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();
        return imagePath;
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
        return null;
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

fos = new BufferedOutputStream(new …

android fileoutputstream

9
推荐指数
3
解决办法
2万
查看次数