要解决“AndroidManifest.xml中设置的‘通知频道尚未由应用程序创建。将使用默认值。’”的问题,你需要在应用程序代码中创建通知频道。请参考以下示例代码:
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private static final String CHANNEL_ID = "your_channel_id";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createNotificationChannel();
}
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence channelName = "Your Channel Name";
String channelDescription = "Your Channel Description";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, channelName, importance);
channel.setDescription(channelDescription);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
}
}
}
...
your_channel_id
通过这些步骤,你将在应用程序中创建一个通知频道,解决"通知频道尚未由应用程序创建"的问题。