在我的Android应用程序中,我通过推送通知从后台启动我的服务.当我收到推送通知时,我正在使用以下代码唤醒我的活动:
Intent it = new Intent("intent.my.action");
it.setComponent(new ComponentName(context.getPackageName(),IncomingActivity.class.getName()));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(it);
Run Code Online (Sandbox Code Playgroud)
一旦我的活动被唤醒,我按下我的主页按钮.当我尝试通过单击最近的应用程序打开我的应用程序时,我的传入活动未显示在最近的应用程序列表中.此方案仅在redmi mi设备中发生,相同的过程适用于摩托罗拉.如何解决这个问题?
上述问题的答案:
我只是在唤醒传入活动时在设备系统托盘中使用自定义通知。在 onCreate() 中,我正在创建自定义通知,然后当传入活动进入 onDestroy() 时清除自定义通知。
我使用下面的代码和方法格式来创建 CustomNotification:
public void setNoticationAfterCallAttendedView(Context view, String callerName, String status,Bitmap bitmap)
{
Intent notificationIntent = new Intent(view, IncomingCallActivity.class);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(view)
.setSmallIcon(R.drawable.logo,3)
.setContentTitle(callerName)
.setOngoing(true)
.setLargeIcon(bitmap)
.setContentText(status) ;
PendingIntent contentIntent = PendingIntent.getActivity(view, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(10000, builder.build());
}
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码和方法格式来清除 CustomNotification:
public void clearNotification()
{
if(this!=null) {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(10000);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这个解决方案对某人有所帮助。每个 Android 架构都有不同,所以为什么我使用这种格式。
谢谢。
| 归档时间: |
|
| 查看次数: |
125 次 |
| 最近记录: |