List of usage examples for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT
int FLAG_ACTIVITY_BROUGHT_TO_FRONT
To view the source code for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT.
Click Source Link
From source file:Main.java
public static void launchApplication(Context context, String pkgname) { Intent intent = context.getPackageManager().getLaunchIntentForPackage(pkgname); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);/*from w w w .j a v a 2 s . c om*/ }
From source file:Main.java
public static void install(Context context, String apkFilePath) { if (context == null) { throw new RuntimeException("ApkUtils install apk method and parameter context == null?"); }/* w w w . j ava 2s. c o m*/ File file = new File(apkFilePath); if (!file.exists()) { return; } Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); context.startActivity(intent); }
From source file:org.secu3.android.api.io.Secu3Notification.java
public Secu3Notification(Context ctx) { this.ctx = ctx; notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); secu3Notification = new NotificationCompat.Builder(ctx) .setContentTitle(ctx.getString(R.string.foreground_service_started_notification_title)) .setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis()).setOngoing(true) .setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, MainActivity.class), Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)) .build();//from ww w. j av a2s.c o m connectionProblemNotification = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.ic_launcher) .setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, MainActivity.class), Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)) .build(); serviceStoppedNotification = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.ic_launcher) .setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, MainActivity.class), Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)) .build(); }
From source file:org.peercast.core.NotificationHelper.java
/** * <pre>/* w w w . j av a2s . co m*/ * [] PeerCast is running... * ??PeerCastMainActivity? */ public NotificationCompat.Builder createDefaultNotification() { Bitmap icon = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_notify_icon); Intent it = new Intent(mService, PeerCastFragment.class); it.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); PendingIntent pi = PendingIntent.getActivity(mService, 0, it, 0); return new NotificationCompat.Builder(mService) // .setSmallIcon(R.drawable.ic_notify_icon) // //.setLargeIcon(icon) // .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setContentIntent(pi)// .setContentTitle("PeerCast running..."); }
From source file:id.zelory.codepolitan.service.NotificationService.java
@Override public void showRandomArticles(List<Article> articles) { Article article = articles.get(0);/* w ww. j av a 2 s . c o m*/ LocalDataManager.saveArticles(articles); LocalDataManager.savePosition(0); Intent intent = new Intent(this, ReadActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); intent.putExtra(ReadActivity.KEY_TYPE, ReadActivity.TYPE_FROM_NOTIF); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(this).setContentTitle("CodePolitan") .setContentText(article.getTitle()).setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true).build(); if (LocalDataManager.getRingtone() != null) { notification.sound = Uri.parse(LocalDataManager.getRingtone()); } if (LocalDataManager.isVibrate()) { notification.vibrate = new long[] { 100, 300, 500 }; } NotificationManagerCompat.from(this).notify(0, notification); }
From source file:com.qasp.diego.arsp.MainActivity.java
@SuppressWarnings("unchecked") @Override// w w w .j ava 2 s .c om protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { // Activity was brought to front and not created, // Thus finishing this will get us to the last viewed activity finish(); return; } // Opcoes padrao para Preferencias. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); setContentView(R.layout.activity_main); // Salva dados se nao for mais visivel if (savedInstanceState != null) { Global.estacoes = (ArrayList<Estacao>) savedInstanceState.getSerializable(ESTADO_ESTACOES); Global.GPS = (Coordenada) savedInstanceState.getSerializable(ESTADO_GPS); } else InicializaEstacoesValidas(Global.estacoes); // Colorizao da barra de servios. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.parseColor("#202020")); } // PERMISSOES verifyStoragePermissions(this); if (PermissaodoGPS(this)) { // Se a permisso ja foi aprovada anterioremente. Intent intent = new Intent(this, LocalizacaoGPSService.class); startService(intent); } // Action bar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // TABS. tablayout = (TabLayout) findViewById(R.id.tab_layout); tablayout.addTab(tablayout.newTab().setText("Lista Estaes")); tablayout.addTab(tablayout.newTab().setText("Indice Local")); tablayout.addTab(tablayout.newTab().setText("Feedback")); tablayout.setTabGravity(TabLayout.GRAVITY_FILL); // PAGER (Deslize) e Funcionamento das Tabs viewPager = (ViewPager) findViewById(R.id.pager); adapter = new PagerAdapter(getSupportFragmentManager(), tablayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout)); tablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { // Notificar eventuais mudanas ao mudar de aba. Global.tabSelecionado = tab.getPosition(); viewPager.setCurrentItem(tab.getPosition()); viewPager.getAdapter().notifyDataSetChanged(); } @Override public void onTabUnselected(TabLayout.Tab tab) { // vazio de proposito } @Override public void onTabReselected(TabLayout.Tab tab) { // Vazio de proposito } }); }
From source file:com.mobile.lapa.waitandsee.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param title/*from w ww. ja va2 s .c o m*/ * @param message GCM message received. */ private void sendNotification(String title, String message) { Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("TITLE_KEY", title); intent.putExtra("MESSAGE_KEY", message); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.game_finished); //Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.sap_logo).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Random random = new Random(); // int notificationId = random.nextInt(9999 - 1000) + 1000; notificationManager.notify(0 /*notificationId*/, notificationBuilder.build()); // -------- Wake up the phone and show the main activity PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock mWakeLock = pm.newWakeLock( (PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MainServiceTag"); mWakeLock.acquire(); // ------- Send notification to the android system startActivity(intent); mWakeLock.release(); }
From source file:com.guardtrax.ui.screens.SplashScreen.java
@Override // Called when activity starts public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //if already running then resume at the last page opened if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { // Activity was brought to front and not created, thus finishing this will get us to the last viewed activity finish();/* ww w. ja va2 s .co m*/ return; } setContentView(R.layout.splashscreen); //Load the GT constants loadGTConstants(); //check directory structure checkDir(); //sync with server syncDB(); //code line below is moved into onClick above when in debug mode initialize(); }
From source file:org.mariotaku.harmony.activity.MusicBrowserActivity.java
public void onClick(final View view) { if (mService == null) return;// ww w. j av a 2s .co m switch (view.getId()) { case R.id.music_browser_control: { if (mService.getTrackInfo() == null) { MusicUtils.shuffleAll(this, mService); } else { final Intent intent = new Intent(this, MusicPlaybackActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); startActivity(intent); } break; } case R.id.play_pause: { if (mService.isPlaying()) { mService.pause(); } else { mService.play(); } break; } case R.id.next: { mService.next(); break; } } }
From source file:com.viettel.dms.util.StatusNotificationHandler.java
/** * //from w w w.j av a 2 s . c o m * tao notification len status notification * @author: AnhND * @param appContext * @param activity * @return: void * @throws: */ private void postNotificationMessage(GlobalBaseActivity activity) { NotificationManager notificationManager = (NotificationManager) GlobalInfo.getInstance().getAppContext() .getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon_app_small; BitmapDrawable bd = (BitmapDrawable) GlobalInfo.getInstance().getAppContext().getResources() .getDrawable(icon); int iconWidth = bd.getBitmap().getWidth(); CharSequence tickerText = getMessageNotify(); long when = System.currentTimeMillis(); // noi dung trong status bar khi keo xuong xem thong bao CharSequence contentText = Constants.STR_BLANK; contentText = getMessageNotify(); int screenWidth = ((WindowManager) GlobalInfo.getInstance().getAppContext() .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth(); screenWidth -= iconWidth;//for icon TextView textView = new TextView(GlobalInfo.getInstance().getAppContext()); int count = tickerText.length(); StringBuilder wrapTickerText = new StringBuilder(); wrapTickerText.append(tickerText); while (count > 0) { if (count < tickerText.length()) { wrapTickerText.append("..."); } float measuredWidth = textView.getPaint().measureText(wrapTickerText.toString()); if (measuredWidth < screenWidth) { break; } count--; wrapTickerText.setLength(count); } Intent notificationIntent = initIntentMessage(); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau int requestCode = (int) System.currentTimeMillis(); PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(), requestCode, notificationIntent, 0); // Notification notification = new Notification(icon, wrapTickerText, when); // Intent notificationIntent = initIntentMessage(); // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau // int requestCode = (int) System.currentTimeMillis(); // PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(), requestCode, notificationIntent, 0); // // notification.setLatestEventInfo(GlobalInfo.getInstance().getAppContext(), StringUtil.getString(R.string.app_name), contentText, contentIntent); // notification.flags |= Notification.FLAG_AUTO_CANCEL; // notification.defaults = Notification.DEFAULT_ALL; // // notificationManager.cancel(NOTIFICATION_MESSAGE_ID); // notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification); NotificationCompat.Builder builder = new NotificationCompat.Builder( GlobalInfo.getInstance().getAppContext()); Notification notification = builder.setContentIntent(contentIntent).setSmallIcon(icon) .setTicker(contentText).setWhen(when).setAutoCancel(true) .setContentTitle(StringUtil.getString(R.string.app_name)).setContentText(contentText).build(); notificationManager.cancel(NOTIFICATION_MESSAGE_ID); notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification); }