我希望仅在通知到来且app已经打开时显示对话框。 如果应用程序像divyabhaskar Android应用程序一样打开,我不想在通知栏上显示通知
答案 0 :(得分:1)
当通知发出以下代码
时[Register("com/indooratlas/android/sdk/resources/IAResourceManager", DoNotGenerateAcw = true)]
public abstract class IAResourceManager : Java.Lang.Object
{
[Register(".ctor", "()V", "")]
public IAResourceManager();
protected IAResourceManager(IntPtr javaReference, JniHandleOwnership transfer);
protected override IntPtr ThresholdClass { get; }
protected override Type ThresholdType { get; }
[Register("create", "(Landroid/content/Context;)Lcom/indooratlas/android/sdk/resources/IAResourceManager;", "")]
public static IAResourceManager Create(Context p0);
[Register("create", "(Landroid/content/Context;Landroid/os/Bundle;)Lcom/indooratlas/android/sdk/resources/IAResourceManager;", "")]
public static IAResourceManager Create(Context p0, Bundle p1);
[Register("fetchFloorPlanWithId", "(Ljava/lang/String;)Lcom/indooratlas/android/sdk/resources/IATask;", "GetFetchFloorPlanWithId_Ljava_lang_String_Handler")]
public abstract IATask FetchFloorPlanWithId(string p0);
}
在您想要对话的活动中注册广播接收器。
Reduce(rbind, d)
接收广播
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am
.getRunningTasks(1);
Log.d("current task :", "CURRENT Activity ::"
+ taskInfo.get(0).topActivity.getClass().getSimpleName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
className = componentInfo.getClassName();
Log.v("", "class Name-" + className);
if (extras != null) {
if (componentInfo.getPackageName().equalsIgnoreCase(
getPackageName())) {
Log.v("", "inside app-");
Intent broadcast = new Intent(ApplicationConstants.MY_BROADCAST);
broadcast.putExtra(ApplicationConstants.BOOKING_ID, bookingId);
broadcast.putExtra(ApplicationConstants.NOTIFICATION_TYPE, type);
broadcast.putExtra(ApplicationConstants.MESSAGE, message);
broadcast.putExtra(ApplicationConstants.CLASS_NAME, className);
LocalBroadcastManager.getInstance(this).sendBroadcast(
broadcast);
Log.v("", "Sending broadcast....");
} else {
sendNotification(extras);
}
在onStop方法中取消注册广播
LocalBroadcastManager.getInstance(this).registerReceiver(receiver,
new IntentFilter(ApplicationConstants.MY_BROADCAST));