0

我正在尝试在 Android中使用此新功能并出现错误

java.lang.NoSuchMethodError: No direct method <init>()V in class Landroid/app/Notification$BubbleMetadata$Builder; or its super classes 

('android.app.Notification$BubbleMetadata$Builder' 的声明出现在 /system/framework/framework.jar 中)

项目正在使用“android-Q”构建,但应用程序在活动开始时崩溃。

这是我在 MainActivity.kt 中使用的示例代码

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Create bubble intent
        val target = Intent(this, MainActivity::class.java)
        val bubbleIntent = PendingIntent.getActivity(this, 0, target, 0 /* flags */)

// Create bubble metadata
        val bubbleData = Notification.BubbleMetadata.Builder()
            .setDesiredHeight(600)
            // Note: although you can set the icon is not displayed in Q Beta 2
            .setIcon(Icon.createWithResource(this, R.drawable.notification_icon_background))
            .setIntent(bubbleIntent)
            .build()

// Create notification
        val chatBot = Person.Builder()
            .setBot(true)
            .setName("BubbleBot")
            .setImportant(true)
            .build()

        val builder = Notification.Builder(this, 11.toString())
            .setContentIntent(bubbleIntent)
            .setSmallIcon(R.drawable.notification_icon_background)
            .setBubbleMetadata(bubbleData)
            //.addPerson(chatBot)

        val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.notify(11, builder.build())


    }
}

AndroidManifest.xml

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 'android-Q'
    defaultConfig {
        applicationId "com.example.mytestapplication"
        targetSdkVersion 28
        minSdkVersion 28
        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"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
4

1 回答 1

3

Q在 Android 中使用 beta 映像进行测试,您需要按照此说明进行操作

实际上,要使用 Q API,您需要安装Android Studio 3.5 Preview并在应用程序中定位 Q android 版本,build.gradle如下所示:

android {
    compileSdkVersion 'android-Q'

    defaultConfig {
       ...
       targetSdkVersion 'Q'
       ...
    }
}
于 2019-05-22T11:37:19.800 回答