Android Gotev Upload Image startForeground的错误通知:java.lang.RuntimeException:服务通知的无效通道

时间:2019-12-21 14:08:14

标签: java android file-upload

我正在使用gotev / android-upload-service创建图像上传器。一切正常,直到选择图像并预览图像。但是,当我单击“发送”按钮时,我的应用因此错误日志而崩溃

AppUser

这是我在AndroidManifest中的许可

Running_Sum([Diff])

这是我的build.gradle

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pmb, PID: 25379
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x42 color=0x00000000 groupKey=net.gotev vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)

这是我的Upload.java

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

这是我的upload.xml

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.pmb"
    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'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.viewpager:viewpager:1.0.0'
implementation 'net.gotev:uploadservice:2.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

我试图检查gotev github,但我只找到了kotlin教程。

如何在Upload.java中使用gotev图片上传或解决问题?

1 个答案:

答案 0 :(得分:0)

将依赖项更改为较新版本的实现'net.gotev:uploadservice:3.4'

然后添加名称空间

`公共类初始化程序扩展了应用程序{

@Override
public void onCreate() {
    super.onCreate();
    // setup the broadcast action namespace string which will
    // be used to notify upload status.
    // Gradle automatically generates proper variable as below.
    UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
    // Or, you can define it manually.
    UploadService.NAMESPACE = "com.example.yourapp";
}

}`

在清单应用程序标签中添加

 android:name=".Initializer"