从TileService启动活动的功能在Android 11中被弃用,因此无法在Android 14上直接使用。然而,您可以通过使用Notification来模拟从TileService启动活动的行为。下面是一个示例代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("tile_channel", "Tile Channel", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
private void showNotification() {
Intent intent = new Intent(this, YourActivity.class); // 替换为您想要启动的活动
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "tile_channel")
.setContentTitle("Tile Action")
.setContentText("Click to open activity")
.setSmallIcon(R.drawable.ic_tile_icon)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, builder.build());
}
@Override
public void onTileAdded() {
super.onTileAdded();
showNotification();
}
现在,当用户添加您的Tile时,它将显示一个Notification,用户可以点击打开您指定的活动。请确保替换YourActivity.class
为您要启动的实际活动类。
上一篇:不允许从另一台机器加载本地图像。
下一篇:不允许从“”请求数据的批量查询。