我使用此代码在屏幕顶部显示通知(例如WhatsApp),但不会付出任何代价,它只显示通知栏上的图标。
TThread.CreateAnonymousThread(
procedure
begin
TThread.Synchronize(TThread.CurrentThread,procedure()
var
pru:integer;
begin
pru := 2;
if NotifAudio then begin
MediaPlayer1.FileName := (TPath.GetDocumentsPath + PathDelim + 'iclassy.mp3');
MediaPlayer1.Play;
end;
BIIntent:= TAndroidHelper.Context.getPackageManager().getLaunchIntentForPackage(TAndroidHelper.Context.getPackageName());
BresultPendingIntent:= TJPendingIntent.JavaClass.getActivity(TAndroidHelper.Context, 0, BIIntent, TJPendingIntent.JavaClass.FLAG_UPDATE_CURRENT);
BntfBuilder:= TJNotificationCompat_Builder.JavaClass.init(TAndroidHelper.Context);
BntfBuilder.setSmallIcon(TAndroidHelper.Context.getResources.getIdentifier(StringToJString('ic_bad_area'), StringToJString('drawable'), TAndroidHelper.Context.getPackageName));
BntfBuilder.setContentTitle(StrToJCharSequence('Title'));
BntfBuilder.setContentText(StrToJCharSequence('Subtext'));
BntfBuilder.setPriority(pru);
BntfBuilder.setContentIntent(BresultPendingIntent);
BntfBuilder.setAutoCancel(False);
if FixNotif2 = True then BntfBuilder.setOngoing(True);
BntfBuilder.setPriority(pru); // priority is set to MAX (2)
BNtf:= BntfBuilder.build;
BadArea_Bool := True;
ntfManager:= TJNotificationManager.Wrap((TAndroidHelper.Context.getSystemService(TJContext.JavaClass.NOTIFICATION_SERVICE) as ILocalObject).GetObjectID);
ntfManager.cancel(1);
ntfManager.notify(2, BNtf);
end);
end).Start();
然而,WhatsApp通知在顶部显示正常,我也尝试了不同的手机,但没有,通知没有在屏幕顶部显示圆角矩形,只需在通知栏上添加小图标。我错过了什么吗?
答案 0 :(得分:0)
解决包括振动:
BntfBuilder.setDefaults(pru); // pru = 2