Example usage for android.content Intent getBooleanExtra

List of usage examples for android.content Intent getBooleanExtra

Introduction

In this page you can find the example usage for android.content Intent getBooleanExtra.

Prototype

public boolean getBooleanExtra(String name, boolean defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.android.gallery3d.app.Gallery.java

private void startViewAction(Intent intent) {
    Boolean slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
    getStateManager().setLaunchGalleryOnTop(true);
    if (slideshow) {
        getActionBar().hide();/*from   ww w. ja va 2s.  co  m*/
        DataManager manager = getDataManager();
        Path path = manager.findPathByUri(intent.getData());
        if (path == null || manager.getMediaObject(path) instanceof MediaItem) {
            path = Path.fromString(manager.getTopSetPath(DataManager.INCLUDE_IMAGE));
        }
        Bundle data = new Bundle();
        data.putString(SlideshowPage.KEY_SET_PATH, path.toString());
        data.putBoolean(SlideshowPage.KEY_RANDOM_ORDER, true);
        data.putBoolean(SlideshowPage.KEY_REPEAT, true);
        getStateManager().startState(SlideshowPage.class, data);
    } else {
        Bundle data = new Bundle();
        DataManager dm = getDataManager();
        Uri uri = intent.getData();
        String contentType = getContentType(intent);
        if (contentType == null) {
            Toast.makeText(this, R.string.no_such_item, Toast.LENGTH_LONG).show();
            finish();
            return;
        }
        if (uri == null) {
            int typeBits = GalleryUtils.determineTypeBits(this, intent);
            data.putInt(KEY_TYPE_BITS, typeBits);
            data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager().getTopSetPath(typeBits));
            getStateManager().setLaunchGalleryOnTop(true);
            getStateManager().startState(AlbumSetPage.class, data);
        } else if (contentType.startsWith(ContentResolver.CURSOR_DIR_BASE_TYPE)) {
            int mediaType = intent.getIntExtra(KEY_MEDIA_TYPES, 0);
            if (mediaType != 0) {
                uri = uri.buildUpon().appendQueryParameter(KEY_MEDIA_TYPES, String.valueOf(mediaType)).build();
            }
            Path setPath = dm.findPathByUri(uri);
            MediaSet mediaSet = null;
            if (setPath != null) {
                mediaSet = (MediaSet) dm.getMediaObject(setPath);
            }
            if (mediaSet != null) {
                if (mediaSet.isLeafAlbum()) {
                    data.putString(AlbumPage.KEY_MEDIA_PATH, setPath.toString());
                    getStateManager().startState(AlbumPage.class, data);
                } else {
                    data.putString(AlbumSetPage.KEY_MEDIA_PATH, setPath.toString());
                    getStateManager().startState(AlbumSetPage.class, data);
                }
            } else {
                startDefaultPage();
            }
        } else {
            Path itemPath = dm.findPathByUri(uri);
            Path albumPath = dm.getDefaultSetOf(itemPath);
            // TODO: Make this parameter public so other activities can reference it.
            boolean singleItemOnly = intent.getBooleanExtra("SingleItemOnly", false);
            if (!singleItemOnly && albumPath != null) {
                data.putString(PhotoPage.KEY_MEDIA_SET_PATH, albumPath.toString());
            }
            data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, itemPath.toString());
            getStateManager().startState(PhotoPage.class, data);
        }
    }
}

From source file:com.ghosthawk.salard.GCM.MyGcmListenerService.java

/**
 * Called when message is received./*from  w w w.ja  v a 2 s.c  o m*/
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String type = data.getString("type");
    String senderid = data.getString("sender");
    String message = data.getString("message");

    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        if (type.equals("chat")) {
            //--TODO 
            String lastDate = DataManager.getInstance().getLastDate(senderid);
            try {
                MessageResult result = NetworkManager.getInstance().getMessageSync(lastDate,
                        PropertyManager.getInstance().getId());
                String notiMessage = null;
                Message u = null;
                for (Message m : result.message) {
                    String id = DataManager.getInstance().getUserTableId(m);
                    DataManager.getInstance().addChatMessage(id, m.member, m.msg_packagenum,
                            DataConstant.ChatTable.TYPE_RECEIVE, m.msg_content, m.msg_date);

                    notiMessage = m.member.mem_name + ":" + m.msg_content;
                    u = m;
                }
                Intent intent = new Intent(CHAT);
                intent.putExtra(EXTRA_SENDER_ID, senderid);
                LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent);
                boolean isProcessed = intent.getBooleanExtra(EXTRA_RESULT, false);
                if (!isProcessed) {
                    sendMessageNotification(notiMessage, u);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        else if (type.equals("follow")) {
            //-TODO 
            sendNotification(message);
        } else if (type.equals("like")) {
            //-TODO 
            sendNotification(message);
        } else if (type.equals("comment")) {
            //-TODO 
            sendNotification(message);
        } else {
            Log.d(TAG, "");
        }
        // normal downstream message.
    }

}

From source file:com.ronnyml.sweetplayer.fragments.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_search, container, false);
    mActivity = this.getActivity();
    mArtistsRecyclerView = (RecyclerView) rootView.findViewById(R.id.top_artists_recyclerview);
    mEditText = (EditText) rootView.findViewById(R.id.search_edit_text);
    mLoadingBar = (ProgressBar) rootView.findViewById(R.id.loading_bar);
    mSearchButton = (ImageButton) rootView.findViewById(R.id.search_button);
    mSongsListview = (ObservableListView) rootView.findViewById(R.id.songs_listview);
    mTopArtistsLayout = (LinearLayout) rootView.findViewById(R.id.top_artists_layout);
    mTopSongsLayout = (LinearLayout) rootView.findViewById(R.id.top_songs_layout);

    LinearLayoutManager mArtistsLinearLayoutManager = new LinearLayoutManager(
            mActivity.getApplicationContext());
    mArtistsLinearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    mArtistsRecyclerView.setLayoutManager(mArtistsLinearLayoutManager);
    mArtistsRecyclerView.setItemAnimator(new DefaultItemAnimator());

    mSongsListview.setScrollViewCallbacks(this);
    setupSearchButton();/*w ww.  j  a  v a  2  s.c  o m*/

    if (Utils.isConnectedToInternet(mActivity)) {
        Intent intent = mActivity.getIntent();
        if (intent != null) {
            if (intent.getBooleanExtra(Constants.IS_SEARCH, false)) {
                search(intent.getStringExtra(Constants.SEARCH_TEXT));
            } else {
                getRequest(Constants.ARTISTS_URL, 0);
                getRequest(Constants.TOP_URL, 1);
            }
        }
    } else {
        Utils.showAlertDialog(mActivity, mActivity.getString(R.string.internet_no_connection_title),
                mActivity.getString(R.string.internet_no_connection_message));
    }

    return rootView;
}

From source file:org.jnegre.android.osmonthego.service.ExportService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_EXPORT_OSM.equals(action)) {
            boolean includeAddress = intent.getBooleanExtra(EXTRA_INCLUDE_ADDRESS, false);
            boolean includeFixme = intent.getBooleanExtra(EXTRA_INCLUDE_FIXME, false);
            handleOsmExport(includeAddress, includeFixme);
        }/*from   w  w w.  j  a  v  a2s  . c  o m*/
    }
}

From source file:com.crowflying.buildwatch.smartwatch.BuildWatchExtensionService.java

private void sendMessage(Intent intent) {
    String message = intent.getStringExtra(getString(R.string.extra_message));
    boolean iBrokeTheBuild = intent.getBooleanExtra(getString(R.string.extra_ifuckedup), false);
    String fullName = intent.getStringExtra(getString(R.string.extra_fullname));
    String url = intent.getStringExtra(getString(R.string.extra_build_url));

    boolean messageSentToWatch = false;
    boolean accessoriesConnected = areAnyAccessoriesConnected();
    Log.i(LOG_TAG,/*from  www.j a  v  a2  s.  c  o  m*/
            String.format("Notifying buildwatch users. Accessories connected: %s", accessoriesConnected));

    if (accessoriesConnected) {
        messageSentToWatch = notifyWatch(message, fullName, url, iBrokeTheBuild);
    }
    if (!messageSentToWatch) {
        // Now, we know not many people have a Sony SmartWatch, so we are
        // trying to bring at least some value to others trying to use this
        // App and show a system notification.
        notifyDevice(message, fullName, url, iBrokeTheBuild);
    }

    // Track whether people actually use the smart watch or just device
    // notifications.
    if (accessoriesConnected) {
        tracker.trackEvent("utilities", "message", "accessory_connected", 1L);
    } else {
        tracker.trackEvent("utilities", "message", "accessory_not_connected", 1L);
    }
    if (messageSentToWatch) {
        tracker.trackEvent("utilities", "message", "message_sent_to_watch", 1L);
    } else {
        tracker.trackEvent("utilities", "message", "message_not_sent_to_watch", 1L);
    }
}

From source file:com.onesignal.NotificationOpenedProcessor.java

static void processIntent(Context incContext, Intent inIntent) {
    context = incContext;//from ww w  . ja v  a 2  s.  c  o m
    intent = inIntent;

    String summaryGroup = intent.getStringExtra("summary");

    boolean dismissed = intent.getBooleanExtra("dismissed", false);

    OneSignalDbHelper dbHelper = new OneSignalDbHelper(context);
    SQLiteDatabase writableDb = dbHelper.getWritableDatabase();

    JSONArray dataArray = null;
    if (!dismissed) {
        try {
            dataArray = NotificationBundleProcessor
                    .newJsonArray(new JSONObject(intent.getStringExtra("onesignal_data")));
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    // We just opened a summary notification.
    if (!dismissed && summaryGroup != null)
        addChildNotifications(dataArray, summaryGroup, writableDb);

    markNotificationsConsumed(writableDb);

    // Notification is not a summary type and is a single notification part of a group.
    if (summaryGroup == null && intent.getStringExtra("grp") != null)
        updateSummaryNotification(writableDb);

    writableDb.close();

    if (!dismissed)
        OneSignal.handleNotificationOpened(context, dataArray, inIntent.getBooleanExtra("from_alert", false));
}

From source file:com.android.calendar.alerts.DismissAlarmsService.java

@Override
public void onHandleIntent(Intent intent) {

    long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1);
    long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
    long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
    boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false);
    long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY);
    long[] eventStarts = intent.getLongArrayExtra(AlertUtils.EVENT_STARTS_KEY);
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1);
    List<AlarmId> alarmIds = new LinkedList<AlarmId>();

    Uri uri = CalendarAlerts.CONTENT_URI;
    String selection;//from w  ww .j ava 2s  .c  om

    // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms
    if (eventId != -1) {
        alarmIds.add(new AlarmId(eventId, eventStart));
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID
                + "=" + eventId;
    } else if (eventIds != null && eventIds.length > 0 && eventStarts != null
            && eventIds.length == eventStarts.length) {
        selection = buildMultipleEventsQuery(eventIds);
        for (int i = 0; i < eventIds.length; i++) {
            alarmIds.add(new AlarmId(eventIds[i], eventStarts[i]));
        }
    } else {
        // NOTE: I don't believe that this ever happens.
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    }

    GlobalDismissManager.dismissGlobally(getApplicationContext(), alarmIds);

    ContentResolver resolver = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    resolver.update(uri, values, selection, null);

    // Remove from notification bar.
    if (notificationId != -1) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(notificationId);
    }

    if (showEvent) {
        // Show event on Calendar app by building an intent and task stack to start
        // EventInfoActivity with AllInOneActivity as the parent activity rooted to home.
        Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd);

        TaskStackBuilder.create(this).addParentStack(EventInfoActivity.class).addNextIntent(i)
                .startActivities();
    }
}

From source file:com.tassadar.multirommgr.MainActivity.java

@Override
public void onFragmentViewCreated() {
    if (++m_fragmentViewsCreated == m_fragments.length) {
        // postDelayed because SwipeRefresher view ignores
        // setRefreshing call otherwise
        m_srLayout.postDelayed(new Runnable() {
            @Override/*from   ww  w . j a  v  a 2s  . co  m*/
            public void run() {
                Intent i = getIntent();
                if (i == null || !i.getBooleanExtra("force_refresh", false)) {
                    startRefresh(true);
                } else {
                    i.removeExtra("force_refresh");
                    refresh();
                }
            }
        }, 1);
    }
}

From source file:org.metawatch.manager.Monitors.java

private static void createWifiReceiver(final Context context) {
    if (wifiReceiver != null)
        return;//from   w w  w . j a v a 2  s  . com
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wm.getConnectionInfo();
    if (info != null)
        SignalData.wifiBars = 1 + WifiManager.calculateSignalLevel(info.getRssi(), 4);
    wifiReceiver = new BroadcastReceiver() {
        int wifiBars = 0;

        @Override
        public void onReceive(Context c, Intent intent) {
            String action = intent.getAction();
            if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
                if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                        WifiManager.WIFI_STATE_UNKNOWN) != WifiManager.WIFI_STATE_ENABLED) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
                if (!intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo netInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                if (netInfo.getState() != NetworkInfo.State.CONNECTED) {
                    wifiBars = 0;
                } else {
                    WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
                    if (wifiInfo == null) {
                        wifiBars = 0;
                    } else {
                        wifiBars = 1 + WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 4);
                    }
                }
            } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
                final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
                wifiBars = 1 + WifiManager.calculateSignalLevel(newRssi, 4);
            }
            if (wifiBars != SignalData.wifiBars) {
                SignalData.wifiBars = wifiBars;
                Idle.updateIdle(context, true);
            }
        }
    };
    IntentFilter f = new IntentFilter();
    f.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    f.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.RSSI_CHANGED_ACTION);
    context.registerReceiver(wifiReceiver, f);
}

From source file:com.android.cts.intent.sender.IntentSenderTest.java

/**
 * The intent receiver will try to read uriNotGranted.
 * Inside the same user, this uri can be read if the receiver has the
 * com.android.cts.managedprofile.permission.SAMPLE permission. But since we cross
 * user-boundaries, it should not be able to (only uri grants work accross users for apps
 * without special permission)./*w w w  . ja v a  2s.  c o m*/
 * We also grant uriGranted to the receiver (this uri belongs to the same content provider as
 * uriNotGranted), to enforce that even if an app has permission to one uri of a
 * ContentProvider, it still cannot access a uri it does not have access to.
 */
public void testAppPermissionsDontWorkAcrossProfiles() throws Exception {
    // The FileProvider does not allow to use app permissions. So we need to use another
    // ContentProvider.
    Uri uriGranted = getBasicContentProviderUri("uri_granted");
    Uri uriNotGranted = getBasicContentProviderUri("uri_not_granted");

    // Granting uriGranted to the receiver
    // Using a persistable permission so that it is kept even after we restart the receiver
    // activity with another intent.
    grantPersistableReadPermission(uriGranted);

    Intent notGrant = new Intent(ACTION_READ_FROM_URI);
    notGrant.setClipData(ClipData.newRawUri("", uriNotGranted));

    final Intent result = mActivity.getResult(notGrant);
    assertNotNull(result);
    // The receiver did not have permission to read the uri. So it should have caught a security
    // exception.
    assertTrue(result.getBooleanExtra("extra_caught_security_exception", false));
}