List of usage examples for android.content Intent addFlags
public @NonNull Intent addFlags(@Flags int flags)
From source file:com.mobiperf.speedometer.AccountSelector.java
private void getAuthToken(AccountManagerFuture<Bundle> result) { Logger.i("getAuthToken() called, result " + result); String errMsg = "Failed to get login cookie. "; Bundle bundle;/*from w w w .j a v a 2s . c o m*/ try { bundle = result.getResult(); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required. (A UI will pop up for user's consent to // allow // this app access account information.) Logger.i("Starting account manager activity"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { Logger.i("Executing getCookie task"); synchronized (this) { this.authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); this.checkinFuture = checkinExecutor.submit(new GetCookieTask()); } } } catch (OperationCanceledException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (AuthenticatorException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (IOException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } }
From source file:app.androidhive.info.realm.GCM.GcmIntentService.java
private void showJSON(String response) { String id;//ww w.j a v a2 s.c o m String name = ""; String adress1 = ""; String adress2 = ""; String phone = ""; try { JSONObject jsonObject = new JSONObject(response); JSONArray result = jsonObject.getJSONArray("Nek"); JSONObject collegeData = result.getJSONObject(0); id = collegeData.getString("ID"); name = collegeData.getString("NekName"); adress1 = collegeData.getString("NekAdress2"); adress2 = collegeData.getString("NekAdress2"); phone = collegeData.getString("NekPhone"); AtomicInteger id2 = new AtomicInteger(); /* if (id == null || id == "" || id == " "){ addInfo(Phone); }*/ //else { Book book = new Book(); book.setId(id2.getAndIncrement()); book.setNekID(id); book.setName(name); book.setPhone(phone); book.setAdress1(adress1); book.setAdress2(adress2); book.setStatus(1); Intent dialogIntent = new Intent(getBaseContext(), MainActivity.class); /* dialogIntent.putExtra("Name", name); dialogIntent.putExtra("Phone", phone); dialogIntent.putExtra("Adress1", adress1); dialogIntent.putExtra("Adress2", adress2); dialogIntent.putExtra("NekID", id); */ dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); // } } catch (JSONException e) { e.printStackTrace(); } }
From source file:RhodesService.java
public static void runApplication(String appName, Object params) { try {/* w ww . j av a 2 s . c om*/ Context ctx = RhodesService.getContext(); PackageManager mgr = ctx.getPackageManager(); PackageInfo info = mgr.getPackageInfo(appName, PackageManager.GET_ACTIVITIES); if (info.activities.length == 0) { Logger.E(TAG, "No activities found for application " + appName); return; } ActivityInfo ainfo = info.activities[0]; String className = ainfo.name; if (className.startsWith(".")) className = ainfo.packageName + className; Intent intent = new Intent(); intent.setClassName(appName, className); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (params != null) { Bundle startParams = new Bundle(); if (params instanceof String) { if (((String) params).length() != 0) { String[] paramStrings = ((String) params).split("&"); for (int i = 0; i < paramStrings.length; ++i) { String key = paramStrings[i]; String value = ""; int splitIdx = key.indexOf('='); if (splitIdx != -1) { value = key.substring(splitIdx + 1); key = key.substring(0, splitIdx); } startParams.putString(key, value); } } } else throw new IllegalArgumentException("Unknown type of incoming parameter"); intent.putExtras(startParams); } ctx.startActivity(intent); } catch (Exception e) { Logger.E(TAG, "Can't run application " + appName + ": " + e.getMessage()); } }
From source file:com.mobilyzer.AccountSelector.java
private void getAuthToken(AccountManagerFuture<Bundle> result) { Logger.i("getAuthToken() called, result " + result); String errMsg = "Failed to get login cookie. "; Bundle bundle;/*w w w . j a v a 2 s . c om*/ try { bundle = result.getResult(); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required. (A UI will pop up for user's consent to allow // this app access account information.) Logger.i("Starting account manager activity"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); } else { Logger.i("Executing getCookie task"); synchronized (this) { this.authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); this.checkinFuture = checkinExecutor.submit(new GetCookieTask()); } } } catch (OperationCanceledException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (AuthenticatorException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (IOException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } }
From source file:com.marianhello.bgloc.LocationService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { log.info("Received start startId: {} intent: {}", startId, intent); if (provider != null) { provider.onDestroy();/*from w w w . j a v a 2 s . c o m*/ } if (intent == null) { //service has been probably restarted so we need to load config from db ConfigurationDAO dao = DAOFactory.createConfigurationDAO(this); try { config = dao.retrieveConfiguration(); } catch (JSONException e) { log.error("Config exception: {}", e.getMessage()); config = new Config(); //using default config } } else { if (intent.hasExtra("config")) { config = intent.getParcelableExtra("config"); } else { config = new Config(); //using default config } } log.debug("Will start service with: {}", config.toString()); LocationProviderFactory spf = new LocationProviderFactory(this); provider = spf.getInstance(config.getLocationProvider()); if (config.getStartForeground()) { // Build a Notification required for running service in foreground. NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(config.getNotificationTitle()); builder.setContentText(config.getNotificationText()); if (config.getSmallNotificationIcon() != null) { builder.setSmallIcon(getDrawableResource(config.getSmallNotificationIcon())); } else { builder.setSmallIcon(android.R.drawable.ic_menu_mylocation); } if (config.getLargeNotificationIcon() != null) { builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(), getDrawableResource(config.getLargeNotificationIcon()))); } if (config.getNotificationIconColor() != null) { builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor())); } // Add an onclick handler to the notification Context context = getApplicationContext(); String packageName = context.getPackageName(); Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR; startForeground(startId, notification); } provider.startRecording(); //We want this service to continue running until it is explicitly stopped return START_STICKY; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.StatusObj.java
@Override public void activate(Context context, SignedObj obj) { //linkify should have picked it up already but if we are in TV mode we //still need to activate Intent intent = new Intent(Intent.ACTION_VIEW); String text = obj.getJson().optString(TEXT); //launch the first thing that looks like a link Matcher m = p.matcher(text);// ww w. j a v a 2 s .co m while (m.find()) { Uri uri = Uri.parse(m.group()); String scheme = uri.getScheme(); if (scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) { intent.setData(uri); if (!(context instanceof Activity)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(intent); return; } } }
From source file:com.snappy.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from w w w . j av a2s . co m private void generateNotification(Context context, String message, String fromName, Bundle pushExtras, String body) { db = new LocalDB(context); List<LocalMessage> myMessages = db.getAllMessages(); // Open a new activity called GCMMessageView Intent intento = new Intent(this, SplashScreenActivity.class); intento.replaceExtras(pushExtras); // Pass data to the new activity intento.putExtra(Const.PUSH_INTENT, true); intento.setAction(Long.toString(System.currentTimeMillis())); intento.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); // Starts the activity on notification click PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT); // Create the notification with a notification builder NotificationCompat.Builder notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis()) .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)) .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true) .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setContentText(body).setContentIntent(pIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)); for (int i = 0; i < myMessages.size(); i++) { inboxStyle.addLine(myMessages.get(i).getMessage()); } notification.setStyle(inboxStyle); // Remove the notification on click //notification.flags |= Notification.FLAG_AUTO_CANCEL; //notification.defaults |= Notification.DEFAULT_VIBRATE; //notification.defaults |= Notification.DEFAULT_SOUND; //notification.defaults |= Notification.DEFAULT_LIGHTS; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(R.string.app_name, notification.build()); { // Wake Android Device when notification received PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH"); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); } }
From source file:com.google.android.apps.muzei.featuredart.FeaturedArtSource.java
@Override protected void onCustomCommand(int id) { super.onCustomCommand(id); if (COMMAND_ID_SHARE == id) { Artwork currentArtwork = getCurrentArtwork(); if (currentArtwork == null) { LOGW(TAG, "No current artwork, can't share."); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override/*from w ww . j a v a2s . co m*/ public void run() { Toast.makeText(FeaturedArtSource.this, R.string.featuredart_source_error_no_artwork_to_share, Toast.LENGTH_SHORT).show(); } }); return; } String detailUrl = ("initial".equals(currentArtwork.getToken())) ? "http://www.wikipaintings.org/en/vincent-van-gogh/the-starry-night-1889" : currentArtwork.getViewIntent().getDataString(); String artist = currentArtwork.getByline().replaceFirst("\\.\\s*($|\\n).*", "").trim(); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, "My Android wallpaper today is '" + currentArtwork.getTitle().trim() + "' by " + artist + ". #MuzeiFeaturedArt\n\n" + detailUrl); shareIntent = Intent.createChooser(shareIntent, "Share artwork"); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareIntent); } else if (COMMAND_ID_DEBUG_INFO == id) { long nextUpdateTimeMillis = getSharedPreferences().getLong("scheduled_update_time_millis", 0); final String nextUpdateTime; if (nextUpdateTimeMillis > 0) { Date d = new Date(nextUpdateTimeMillis); nextUpdateTime = SimpleDateFormat.getDateTimeInstance().format(d); } else { nextUpdateTime = "None"; } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(FeaturedArtSource.this, "Next update time: " + nextUpdateTime, Toast.LENGTH_LONG) .show(); } }); } }
From source file:com.google.zxing.client.android.result.ResultHandler.java
/** * Like {@link #launchIntent(Intent)} but will tell you if it is not handle-able * via {@link ActivityNotFoundException}. * * @throws ActivityNotFoundException/*from w w w .j av a2s.c o m*/ */ final void rawLaunchIntent(Intent intent) { if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); Log.d(TAG, "Launching intent: " + intent + " with extras: " + intent.getExtras()); activity.startActivity(intent); } }
From source file:com.codebutler.farebot.activities.AddKeyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_key); getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT); findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { @Override// w w w .j av a2 s .com public void onClick(View view) { setResult(RESULT_CANCELED); finish(); } }); findViewById(R.id.add).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final String keyType = ((RadioButton) findViewById(R.id.is_key_a)).isChecked() ? ClassicSectorKey.TYPE_KEYA : ClassicSectorKey.TYPE_KEYB; new BetterAsyncTask<Void>(AddKeyActivity.this, true, false) { @Override protected Void doInBackground() throws Exception { ClassicCardKeys keys = ClassicCardKeys.fromDump(keyType, mKeyData); ContentValues values = new ContentValues(); values.put(KeysTableColumns.CARD_ID, mTagId); values.put(KeysTableColumns.CARD_TYPE, mCardType); values.put(KeysTableColumns.KEY_DATA, keys.toJSON().toString()); getContentResolver().insert(CardKeyProvider.CONTENT_URI, values); return null; } @Override protected void onResult(Void unused) { Intent intent = new Intent(AddKeyActivity.this, KeysActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } }.execute(); } }); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); Utils.checkNfcEnabled(this, mNfcAdapter); Intent intent = getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0); if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_VIEW) && getIntent().getData() != null) { try { InputStream stream = getContentResolver().openInputStream(getIntent().getData()); mKeyData = IOUtils.toByteArray(stream); } catch (IOException e) { Utils.showErrorAndFinish(this, e); } } else { finish(); } }