gpt4 book ai didi

android - 创建NotificationChannel会抛出IllegalArgumentException

转载 作者:行者123 更新时间:2023-12-02 17:47:18 25 4
gpt4 key购买 nike

该应用适用于以前版本的 Android,但不适用于 Oreo。它是一个带有 NotificationWebView。我一直在研究这个错误,但没有发现任何类似的内容。

堆栈跟踪:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.oneteamit.tk, PID: 3171
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.oneteamit.tk/net.oneteamit.tk.MainActivity}:
java.lang.IllegalArgumentException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException
at android.os.Parcel.readException(Parcel.java:1946)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:1418)
at android.app.NotificationManager.createNotificationChannels(NotificationManager.java:446)
at android.app.NotificationManager.createNotificationChannel(NotificationManager.java:434)
at net.oneteamit.tk.MainActivity.onCreate(MainActivity.java:47)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

主 Activity :

public class MainActivity extends AppCompatActivity {

private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("My test URL");
mWebView.setWebViewClient(new WebViewClient());
mWebView.getSettings().setAppCacheEnabled(false);
mWebView.clearCache(true);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create channel to show notifications.
String channelId = getString(R.string.default_notification_channel_id);
String channelName = getString(R.string.default_notification_channel_name);

NotificationManager notificationManager =
getSystemService(NotificationManager.class);

notificationManager.createNotificationChannel(
new NotificationChannel(channelId,
channelName,
NotificationManager.IMPORTANCE_LOW));
}

mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.setInitialScale(1);
mWebView.getSettings().setBuiltInZoomControls(true);
}
}

最佳答案

当 channel 名称无效时会发生此异常。我能够通过使用空 channel 名称运行来重现堆栈跟踪:

<string name="default_notification_channel_name"></string>

检查您为 default_notification_channel_name 定义的值并将其更改为有效值。

关于android - 创建NotificationChannel会抛出IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49072959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com