ブロードキャストを起動するアプリがあります。アプリが実行されている場合はどのアクティビティでもポップアップを表示し、そうでない場合は通知をプッシュします
これが私のコードです
public class AlarmReceiver extends BroadcastReceiver
{
private static int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
@Override
public void onReceive(final Context ctx, Intent intent)
{
if (isRunning(ctx))
{
Intent myIntent = new Intent (ctx, NotifyTagabilityCounter.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(myIntent);
}
else
{
mNotificationManager = (NotificationManager)
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
Intent i = new Intent(ctx, Game.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(Constants.TAG_TIMESTAMP, true);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
i, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.launcher)
Notification notification = mBuilder.getNotification();
notification.flags = Notification.FLAG_AUTO_CANCEL;
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);
SharedPreferences customSharedPreference = ctx.getSharedPreferences(
"UserSharedPrefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference.edit();
editor.putBoolean(Constants.TAG_NOTIFICATION, true);
editor.commit();
}
}
public boolean isRunning(Context ctx)
{
ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (RunningTaskInfo task : tasks)
{
if (ctx.getPackageName().equalsIgnoreCase(
task.baseActivity.getPackageName()))
return true;
}
return false;
}
新しいアクティビティの作成についてNotificyTagabilityCounter
ublic class NotifyTagabilityCounter extends Activity
{
public static final int NOTIFICATION_ID_RECEIVED = 0x1221;
static final String ACTION = "com.trib.broadcast";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
IntentFilter filter = new IntentFilter(ACTION);
this.registerReceiver(mReceivedReceiver, filter);
}
private final BroadcastReceiver mReceivedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION.equals(action))
{
displayAlert();
}
}
};
私が得るのは黒い画面だけです。最後のアクティビティを表示し、その上にポップアップ AlertDisplay を表示します。これはどのように行うことができますか..?