【发布时间】:2020-01-24 14:07:26
【问题描述】:
我正在开发一个 Android 应用程序,我想在状态栏中添加一个电话按钮。我可以在状态栏中添加电话按钮吗?
我想添加一个按钮,如上图所示。我尝试处理通知,但通知图标大小太小。我该怎么做?有什么想法吗?
【问题讨论】:
我正在开发一个 Android 应用程序,我想在状态栏中添加一个电话按钮。我可以在状态栏中添加电话按钮吗?
我想添加一个按钮,如上图所示。我尝试处理通知,但通知图标大小太小。我该怎么做?有什么想法吗?
【问题讨论】:
我认为在状态栏中放置一个按钮违反了设计准则,因为它应该只包含通知和系统图标。见https://material.io/design/platform-guidance/android-bars.html#status-bar。
尝试使用提醒通知 (https://developer.android.com/guide/topics/ui/notifiers/notifications.html)。 您可以将按钮放在通知的操作区域(https://material.io/design/platform-guidance/android-notifications.html#anatomy-of-a-notification)。
【讨论】:
看起来您需要带有通知图标的前台服务 - here
前台服务示例代码 -
public class ExampleService extends Service {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String input = intent.getStringExtra("inputExtra");
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Example Service")
.setContentText(input)
.setSmallIcon(R.drawable.ic_android)
.setContentIntent(pendingIntent)
.build();
startForeground(1, notification);
//do heavy work on a background thread
//stopSelf();
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
【讨论】: