android Oreo Crash错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android Oreo Crash错误相关的知识,希望对你有一定的参考价值。

该应用程序适用于以前版本的android,但不适用于Oreo,它是使用Firebase通知的Web视图。我对此有点新,但一直在研究这个错误,并没有发现任何类似的东西。

---------崩溃的开始

E / AndroidRuntime:FATAL EXCEPTION:main进程:net.oneteamit.tk,PID:3171 java.lang.RuntimeException:无法启动活动ComponentInfo {net.oneteamit.tk/net.oneteamit.tk.MainActivity}:java.lang。 android.app.A活动时的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)中的android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)的android.app.ActivityThread.-wrap11(未知来源:0)的IllegalArgumentException .ActivityThread $ H.handleMessage(ActivityThread.java:1593)在android.app.Loper.loop(Looper.java:164)的android.app.A.运行时,在android.app.ActivityThread的android.os.Handler.dispatchMessage(Handler.java:105)。 main(ActivityThread.java:6541)位于com.android.internal的com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240)的java.lang.reflect.Method.invoke(Native Method)。 os.ZygoteInit.main(ZygoteInit.java:767)由android.os.Parcel.readException(Parcel上的android.os.Parcel.readException(Parcel.java:1946)中的java.lang.IllegalArgumentException引起.java:1888)在Android.app.NotificationManager.createNotificationChannel(NotificationManager)的android.app.otificationManager $ Stub $ Proxy.createNotificationChannels(INotificationManager.java:1418)android.app.NotificationManager.createNotificationChannels(NotificationManager.java:446)。 java:434)在net.oneteamit.tk.MainActivity.onCreate(MainActivity.java:47)android.app.Activity.performCreate(Activity.java:6975)android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) )android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)在Android.app的android.app.ActivityThread.- wrap11(未知来源:0)的android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) .ActivityThread $ H.handleMessage(ActivityThread.java:1593)在android.app.Loper.loop(Looper.java:164)的android.app.A.运行时,在android.app.ActivityThread的android.os.Handler.dispatchMessage(Handler.java:105)。 main(ActivityThread.java:6541)at java.lang.reflect.Method.invoke(Native M ethod)com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)W / cr_media:需要BLUETOOTH权限应用程序终止。

public class MainActivity extends AppCompatActivity {

private WebView mWebView;


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






    //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()); //I DISABLED THIS TO HAVE IT OPEN in browser
    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));
    }
    //webSettings.setDomStorageEnabled (true);
    //mWebView.getSettings().setDomStorageEnabled(true);
    //mWebView.getSettings().setDatabaseEnabled(true);
    //mWebView.getSettings().setAppCacheEnabled(true);
    //mWebView.getSettings().setJavaScriptEnabled(true);
    //mWebView.setFocusable(false);
    //mWebView.setFocusableInTouchMode(false);
    //mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    // mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    //mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    //mWebView.setScrollbarFadingEnabled(false);
    //this.mWebView.setVerticalScrollBarEnabled(true);
    //this.mWebView.setHorizontalScrollBarEnabled(true);
    mWebView.getSettings().setUseWideViewPort(true);//setting wide view
    mWebView.getSettings().setLoadWithOverviewMode(true);//setting default zoomed out view
    mWebView.setInitialScale(1);
    mWebView.getSettings().setBuiltInZoomControls(true);//setting zoom controls

}

@Override
public void onBackPressed() {
    if(mWebView.canGoBack()) {
        mWebView.goBack();
    } else {
        super.onBackPressed();
    }
}



@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

表现

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">


    <!-- Set custom default icon. This is used when no icon is set for incoming notification messages.

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@mipmap/ic_launcher" />
    <!-- the location above will tell the app where to look for your notification Icon -->


    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id"/>



    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.androidsrc.launchfrombrowser" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>

    </activity>





    <service android:name=".FirebaseInstanceIdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <service android:name=".FirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name=".MyJobService"
             android:exported="false">
    <intent-filter>
        <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
    </intent-filter>
    </service>
</application>
<uses-permission android:name="android.permission.INTERNET" />

答案

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

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

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

另一答案

AppCompactActivity是向后兼容但不向前兼容,您使用的是Android 8.0不支持的任何组件,还是Android Studio或最新的Oreo IDE。

以上是关于android Oreo Crash错误的主要内容,如果未能解决你的问题,请参考以下文章

片段中的Android按钮单击方法(崩溃)

Android Oreo 上未添加地理围栏

Android Studio 无法识别 Oreo 的最新版本代码或新窗口类型

Android 8或更高版本使用Firebase Performance SDK在Android Oreo上崩溃的应用程序

ScanCall回来没有进入Android Oreo

Android Nougat,Oreo - 如何将长按动作添加到快速切换?