前台服务通知在 Android 12 上显示太慢。使用过ContextCompat.startForegroundService(...)
和mContext.startForegroundService(...)
。5-10 秒后仍会显示。
这是我的代码的示例:
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Counting steps", NotificationManager.IMPORTANCE_DEFAULT);
channel.enableVibration(false);
channel.setSound(null, null);
channel.setShowBadge(false);
notificationManager.createNotificationChannel(channel);
}
}
Run Code Online (Sandbox Code Playgroud)
onStartCommand方法:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String input = intent.getStringExtra("numberOfSteps");
createNotificationChannel();
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
Notification.Builder notificationBuilder = new Notification.Builder(this, CHANNEL_ID)
.setContentTitle("Counting steps")
.setContentText(input)
.setSmallIcon(R.drawable.ic_baseline_directions_walk_24)
.setContentIntent(pendingIntent);
startForeground(FOREGROUND_ID, …
Run Code Online (Sandbox Code Playgroud) 我在坐标布局中有一个 BottomSheet。在正常情况下完美运行。当 Android 使用屏幕手势而不是导航按钮时,会出现问题。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/episode_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
app:behavior_hideable="false"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
Run Code Online (Sandbox Code Playgroud)
使用手势导航时
我已经尝试过否定,app:behavior_peekHeight
但它不起作用。但当我给出 app:behavior_peekHeight="@dimen/_45sdp"
它时,它显示播放器控制器,但也显示底部布局。我想隐藏底部布局。