標籤

2020年3月16日 星期一

android10的坑,sdcard不能讀寫,notification不會通知 (解決方法在此)

在安卓9執行的好好的app
升級到android 10就又不能正常運作

過程就不多說了,直接把我解決問題的方法,留下紀綠

1. sdcard
sdcard的讀寫要正常,不用改程式,只需在 androidmanifest.xml 加上一行,就可以了
<application    android:allowBackup="true"    android:icon="@mipmap/ic_launcher"
//  加上下面這行    android:requestLegacyExternalStorage="true"              

2.notification

問題的原因是 android 10 要求有 channel id
加上這樣,就ok了

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
    String channelId = "bpviwer_channel_id";
    NotificationChannel channel = new NotificationChannel(
            channelId,
            "bpviwer_channel",
            NotificationManager.IMPORTANCE_HIGH);
    mNotificationManager.createNotificationChannel(channel);
    mBuilder.setChannelId(channelId);
}


這樣就耗了兩天的時間了

沒有留言:

張貼留言