브로드 캐스트를 시작하는 앱이 있습니다. 내가 아무리 앱이 실행되지 다음 경우에하는 통지 여기활동 호출 Alert Box from Broadcast Receiver android
를 밀어하면 생각하는 활동에 팝업을 표시하지 싶은 새로운 활동을 만드는 방법에 대한 내 코드
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가 표시됩니다. 이게 어떻게 .. 할 수 있니?
동일한 작업을 수행했지만 기본 작업에서 팝업 및 서버 호출을 정의해야합니까? 어떻게하면 제대로 호출 할 수 있습니까? 예를 들어 주시겠습니까? 내 브로드 캐스트 수신기에서 BaseActivty 브로드 캐스트로 브로드 캐스트를 보내고 있지만 토큰 null로 팝업을 만드는 동안 오류가 발생합니다. –