Example usage for android.content Intent getParcelableExtra

List of usage examples for android.content Intent getParcelableExtra

Introduction

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

Prototype

public <T extends Parcelable> T getParcelableExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.gsma.rcs.ri.messaging.OneToOneTalkView.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;//from w  ww.j  av a 2 s. c om
    }
    switch (requestCode) {
    case SELECT_GEOLOCATION:
        Geoloc geoloc = data.getParcelableExtra(EditGeoloc.EXTRA_GEOLOC);
        try {
            if (mChat != null) {
                mChat.sendMessage(geoloc);
            }
        } catch (RcsServiceException e) {
            showExceptionThenExit(e);
        }
        break;
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void onActivityResult(final Activity mActivity, GoogleApiClient gapi, final int requestCode,
        final int resultCode, final Intent data) {
    SettingsManager sm = new SettingsManager(mActivity);
    if (gapi == null)
        gapi = GoogleDrive.gapi;/* w w w. ja va  2s. c  om*/
    switch (requestCode) {
    case RESOLVE_CONNECTION_REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            if (DEBUG) {
                Log.d(TAG, "App connect +1");
            }
            gapi.connect();
        } else {
            if (DEBUG) {
                Log.d(TAG, "App cannot connect");
            }
            final GoogleApiClient finalGapi = gapi;
            new MaterialDialog.Builder(mActivity).title(R.string.connection_issue_title)
                    .content(R.string.connection_issue_description).positiveText(R.string.ok)
                    .negativeText(R.string.try_again).callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);
                            finalGapi.connect();
                        }
                    }).show();
        }
        break;
    case REQUEST_CODE_CREATOR:
        if (data == null || !gapi.isConnected()) {
            // If op was canceled
            return;
        }
        DriveId driveId = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
        if (DEBUG) {
            Log.d(TAG, driveId.encodeToString() + ", " + driveId.getResourceId() + ", "
                    + driveId.toInvariantString());
        }
        sm.setString(R.string.sm_google_drive_id, driveId.encodeToString());

        DriveFile file = Drive.DriveApi.getFile(gapi, DriveId.decodeFromString(driveId.encodeToString()));
        //Write initial data
        ActivityUtils.writeDriveData(mActivity, gapi);
        break;
    case ActivityUtils.REQUEST_CODE_OPENER:
        if (data == null) //If op was canceled
            return;
        driveId = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
        if (DEBUG) {
            Log.d(TAG, driveId.encodeToString() + ", " + driveId.getResourceId() + ", "
                    + driveId.toInvariantString());
        }
        sm.setString(R.string.sm_google_drive_id, driveId.encodeToString());
        final GoogleApiClient finalGapi1 = gapi;
        new MaterialDialog.Builder(mActivity).title(R.string.sync_initial)
                .positiveText(R.string.sync_cloud_local).negativeText(R.string.sync_local_cloud)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        ActivityUtils.readDriveData(mActivity, finalGapi1);
                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);
                        ActivityUtils.writeDriveData(mActivity, finalGapi1);
                    }
                }).show();
    }
}

From source file:com.folioreader.activity.FolioActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTION_CONTENT_HIGHLIGHT && resultCode == RESULT_OK && data.hasExtra(TYPE)) {

        String type = data.getStringExtra(TYPE);
        if (type.equals(CHAPTER_SELECTED)) {
            mChapterPosition = data.getIntExtra(SELECTED_CHAPTER_POSITION, 0);
            int spineRefrencesPos = AppUtil.getSpineRefrecePos(mSpineReferences,
                    mTocReferences.get(mChapterPosition));
            mFolioPageViewPager.setCurrentItem(spineRefrencesPos);
        } else if (type.equals(HIGHLIGHT_SELECTED)) {
            Highlight highlight = data.getParcelableExtra(HIGHLIGHT_ITEM);
            int position = highlight.getCurrentPagerPostion();
            mFolioPageViewPager.setCurrentItem(position);
            WebViewPosition webViewPosition = new WebViewPosition();
            webViewPosition.setWebviewPos(highlight.getCurrentWebviewScrollPos());
            BUS.post(webViewPosition);/*from  w w  w . j a  v a2  s  .c  o  m*/
        }
    }
}

From source file:com.orpheusdroid.screenrecorder.RecorderService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    //return super.onStartCommand(intent, flags, startId);
    //Find the action to perform from intent
    switch (intent.getAction()) {
    case Const.SCREEN_RECORDING_START:
        /* Wish MediaRecorder had a method isRecording() or similar. But, we are forced to
         * manage the state ourself. Let's hope the request is honored.
          * Request: https://code.google.com/p/android/issues/detail?id=800 */
        if (!isRecording) {
            //Get values from Default SharedPreferences
            getValues();/*from w ww.  ja  v a2 s. com*/
            Intent data = intent.getParcelableExtra(Const.RECORDER_INTENT_DATA);
            int result = intent.getIntExtra(Const.RECORDER_INTENT_RESULT, Activity.RESULT_OK);

            //Initialize MediaRecorder class and initialize it with preferred configuration
            mMediaRecorder = new MediaRecorder();
            initRecorder();

            //Set Callback for MediaProjection
            mMediaProjectionCallback = new MediaProjectionCallback();
            MediaProjectionManager mProjectionManager = (MediaProjectionManager) getSystemService(
                    Context.MEDIA_PROJECTION_SERVICE);

            //Initialize MediaProjection using data received from Intent
            mMediaProjection = mProjectionManager.getMediaProjection(result, data);
            mMediaProjection.registerCallback(mMediaProjectionCallback, null);

            /* Create a new virtual display with the actual default display
             * and pass it on to MediaRecorder to start recording */
            mVirtualDisplay = createVirtualDisplay();
            try {
                mMediaRecorder.start();
                isRecording = true;
                Toast.makeText(this, R.string.screen_recording_started_toast, Toast.LENGTH_SHORT).show();
            } catch (IllegalStateException e) {
                Log.d(Const.TAG,
                        "Mediarecorder reached Illegal state exception. Did you start the recording twice?");
                Toast.makeText(this, R.string.recording_failed_toast, Toast.LENGTH_SHORT).show();
                isRecording = false;
            }

            /* Add Pause action to Notification to pause screen recording if the user's android version
             * is >= Nougat(API 24) since pause() isnt available previous to API24 else build
             * Notification with only default stop() action */
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                //startTime is to calculate elapsed recording time to update notification during pause/resume
                startTime = System.currentTimeMillis();
                Intent recordPauseIntent = new Intent(this, RecorderService.class);
                recordPauseIntent.setAction(Const.SCREEN_RECORDING_PAUSE);
                PendingIntent precordPauseIntent = PendingIntent.getService(this, 0, recordPauseIntent, 0);
                NotificationCompat.Action action = new NotificationCompat.Action(
                        android.R.drawable.ic_media_pause,
                        getString(R.string.screen_recording_notification_action_pause), precordPauseIntent);

                //Start Notification as foreground
                startNotificationForeGround(createNotification(action).build(),
                        Const.SCREEN_RECORDER_NOTIFICATION_ID);
            } else
                startNotificationForeGround(createNotification(null).build(),
                        Const.SCREEN_RECORDER_NOTIFICATION_ID);
        } else {
            Toast.makeText(this, R.string.screenrecording_already_active_toast, Toast.LENGTH_SHORT).show();
        }
        break;
    case Const.SCREEN_RECORDING_PAUSE:
        pauseScreenRecording();
        break;
    case Const.SCREEN_RECORDING_RESUME:
        resumeScreenRecording();
        break;
    case Const.SCREEN_RECORDING_STOP:
        stopScreenSharing();
        //The service is started as foreground service and hence has to be stopped
        stopForeground(true);
        break;
    }
    return START_STICKY;
}

From source file:com.ubuntuone.android.files.service.MetaService.java

@Override
protected void onHandleIntent(Intent intent) {
    sSyncRunning = true;//from   w ww  .  ja va 2  s . c  om
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

    final String action = intent.getAction();
    final String resourcePath = intent.getStringExtra(EXTRA_RESOURCE_PATH);
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_CALLBACK);

    if (ACTION_GET_USER.equals(action)) {
        getUser(receiver);
        getVolumes(receiver);
    } else if (ACTION_GET_VOLUME.equals(action)) {
        getVolume(resourcePath, receiver);
    } else if (ACTION_CREATE_VOLUME.equals(action)) {
        createVolume(resourcePath, receiver);
    } else if (ACTION_MAKE_DIRECTORY.equals(action)) {
        makeDirectory(resourcePath, receiver);
    } else if (ACTION_GET_NODE.equals(action)) {
        getNode(resourcePath, receiver, true);
    } else if (ACTION_UPDATE_NODE.equals(action)) {
        if (intent.hasExtra(Nodes.NODE_NAME)) {
            String newPath = intent.getStringExtra(EXTRA_PATH);
            updateNode(resourcePath, newPath, receiver);
        }
        if (intent.hasExtra(Nodes.NODE_IS_PUBLIC)) {
            Boolean isPublic = intent.getBooleanExtra(Nodes.NODE_IS_PUBLIC, false);
            updateNode(resourcePath, isPublic, receiver);
        }
    } else if (ACTION_DELETE_NODE.equals(action)) {
        deleteNode(resourcePath, receiver);
    }
    sSyncRunning = false;
}

From source file:com.mattprecious.prioritysms.activity.ProfileListActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (iabHelper != null && iabHelper.handleActivityResult(requestCode, resultCode, data)) {
        return;//from  www.  j a  v a  2 s .  c o m
    }

    switch (requestCode) {
    case REQUEST_ID_PROFILE_EDIT:
        switch (resultCode) {
        case RESULT_OK:
            showSaveCrouton();
            break;
        case RESULT_CANCELED:
            showDiscardCrouton();
            break;
        case ProfileDetailActivity.RESULT_DELETED:
            showDeleteCrouton((BaseProfile) data.getParcelableExtra(ProfileDetailFragment.EXTRA_PROFILE));
            break;
        default:
            break;
        }
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:com.connectsdk.discovery.DiscoveryManager.java

/**
 * Create a new instance of DiscoveryManager.
 * Direct use of this constructor is not recommended. In most cases,
 * you should use DiscoveryManager.getInstance() instead.
 *//*w  w w .j a  va 2  s .c o m*/
public DiscoveryManager(Context context, ConnectableDeviceStore connectableDeviceStore) {
    this.context = context;
    this.connectableDeviceStore = connectableDeviceStore;

    allDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2);
    compatibleDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2);

    deviceClasses = new ConcurrentHashMap<String, Class<? extends DeviceService>>(4, 0.75f, 2);
    discoveryProviders = new CopyOnWriteArrayList<DiscoveryProvider>();

    discoveryListeners = new CopyOnWriteArrayList<DiscoveryManagerListener>();

    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    multicastLock = wifiMgr.createMulticastLock("Connect SDK");
    multicastLock.setReferenceCounted(true);

    capabilityFilters = new ArrayList<CapabilityFilter>();
    pairingLevel = PairingLevel.OFF;

    receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);

                switch (networkInfo.getState()) {
                case CONNECTED:
                    if (mSearching) {
                        for (DiscoveryProvider provider : discoveryProviders) {
                            provider.start();
                        }
                    }

                    break;

                case DISCONNECTED:
                    Log.w("Connect SDK", "Network connection is disconnected");

                    for (DiscoveryProvider provider : discoveryProviders) {
                        provider.reset();
                    }

                    allDevices.clear();

                    for (ConnectableDevice device : compatibleDevices.values()) {
                        handleDeviceLoss(device);
                    }
                    compatibleDevices.clear();

                    for (DiscoveryProvider provider : discoveryProviders) {
                        provider.stop();
                    }

                    break;

                case CONNECTING:
                    break;
                case DISCONNECTING:
                    break;
                case SUSPENDED:
                    break;
                case UNKNOWN:
                    break;
                }
            }
        }
    };

    registerBroadcastReceiver();
}

From source file:com.dsi.ant.antplus.pluginsampler.weightscale.Activity_WeightScaleSampler.java

/**
 * Resets the PCC connection to request access again and clears any existing display data.
 *///from   w w w.  j  a va 2  s.c  o  m
private void resetPcc() {
    //Release the old access if it exists
    if (releaseHandle != null) {
        releaseHandle.close();
    }

    //Reset the text display
    tv_status.setText("Connecting...");

    setRequestButtonsEnabled(false);
    resetWeightRequestedDataDisplay("---");
    tv_bodyWeightBroadcast.setText("---");

    tv_estTimestamp.setText("---");

    tv_hardwareRevision.setText("---");
    tv_manufacturerID.setText("---");
    tv_modelNumber.setText("---");

    tv_mainSoftwareRevision.setText("---");
    tv_supplementalSoftwareRevision.setText("");
    tv_serialNumber.setText("---");

    Intent intent = getIntent();
    if (intent.hasExtra(Activity_MultiDeviceSearchSampler.EXTRA_KEY_MULTIDEVICE_SEARCH_RESULT)) {
        // device has already been selected through the multi-device search
        MultiDeviceSearchResult result = intent
                .getParcelableExtra(Activity_MultiDeviceSearchSampler.EXTRA_KEY_MULTIDEVICE_SEARCH_RESULT);
        releaseHandle = AntPlusWeightScalePcc.requestAccess(this, result.getAntDeviceNumber(), 0,
                mResultReceiver, mDeviceStateChangeReceiver);
    } else {
        // starts the plugins UI search
        releaseHandle = AntPlusWeightScalePcc.requestAccess(this, this, mResultReceiver,
                mDeviceStateChangeReceiver);
    }
}

From source file:com.gsma.rcs.ri.messaging.OneToOneTalkView.java

private boolean processIntent(Intent intent) {
    String action = intent.getAction();
    if (LogUtils.isActive) {
        Log.d(LOGTAG, "processIntent " + action);
    }//from  ww w .jav a2 s. c o m
    ContactId newContact = intent.getParcelableExtra(EXTRA_CONTACT);
    if (newContact == null) {
        if (LogUtils.isActive) {
            Log.w(LOGTAG, "Cannot process intent: contact is null");
        }
        return false;
    }
    if (action == null) {
        if (LogUtils.isActive) {
            Log.w(LOGTAG, "Cannot process intent: action is null");
        }
        return false;
    }
    if (!sAllowedIntentActions.contains(action)) {
        if (LogUtils.isActive) {
            Log.w(LOGTAG, "Cannot process intent: unauthorized action " + action);
        }
        return false;
    }
    try {
        if (!newContact.equals(mContact)) {
            /* Either it is the first conversation loading or switch to another conversation */
            loadConversation(newContact);
        }
        /* Set activity title with display name */
        String displayName = RcsContactUtil.getInstance(this).getDisplayName(mContact);
        setTitle(getString(R.string.title_chat, displayName));
        switch (action) {
        case OneToOneChatIntent.ACTION_NEW_ONE_TO_ONE_CHAT_MESSAGE:
            /*
             * Open chat to accept session if the parameter IM SESSION START is 0. Client
             * application is not aware of the one to one chat session state nor of the IM
             * session start mode so we call the method systematically.
             */
            mChat.openChat();
            break;

        case OneToOneChatIntent.ACTION_MESSAGE_DELIVERY_EXPIRED:
            processUndeliveredMessages(displayName);
            break;

        case FileTransferIntent.ACTION_FILE_TRANSFER_DELIVERY_EXPIRED:
            processUndeliveredFileTransfers(displayName);
            break;
        }
        return true;

    } catch (RcsServiceException e) {
        showExceptionThenExit(e);
        return false;
    }
}

From source file:net.exclaimindustries.geohashdroid.services.WikiService.java

@Override
protected void serializeToDisk(Intent i, OutputStream os) {
    // We'll encode one line per object, with the last lines reserved for
    // the entire message (the only thing of these that can have multiple
    // lines)./*from  w  ww . j  a v  a  2s  .  c o m*/
    OutputStreamWriter osw = new OutputStreamWriter(os);
    StringBuilder builder = new StringBuilder();

    // Always write out the \n, even if it's null.  An empty line will be
    // deserialized as a null.  Yes, even if that'll cause an error later.

    // The date can come in as a long.
    Calendar c = (Calendar) i.getParcelableExtra(EXTRA_TIMESTAMP);
    if (c != null)
        builder.append(c.getTimeInMillis());
    builder.append('\n');

    // The location is just two doubles.  Split 'em with a colon.
    Location loc = (Location) i.getParcelableExtra(EXTRA_LOCATION);
    if (loc != null)
        builder.append(Double.toString(loc.getLatitude())).append(':')
                .append(Double.toString(loc.getLongitude()));
    builder.append('\n');

    // The image is just a URI.  Easy so far.
    Uri uri = (Uri) i.getParcelableExtra(EXTRA_IMAGE);
    if (uri != null)
        builder.append(uri.toString());
    builder.append('\n');

    // And now comes Info.  It encompasses two doubles (the destination),
    // a Date (the date of the expedition), and a Graticule (two ints
    // and two booleans).  The Graticule part can be null if this is a
    // globalhash.
    Info info = (Info) i.getParcelableExtra(EXTRA_INFO);
    if (info != null) {
        builder.append(Double.toString(info.getLatitude())).append(':')
                .append(Double.toString(info.getLongitude())).append(':')
                .append(Long.toString(info.getDate().getTime())).append(':');

        if (!info.isGlobalHash()) {
            Graticule g = info.getGraticule();
            builder.append(Integer.toString(g.getLatitude())).append(':').append(g.isSouth() ? '1' : '0')
                    .append(':').append(Integer.toString(g.getLongitude())).append(':')
                    .append((g.isWest() ? '1' : '0'));
        }
    }
    builder.append('\n');

    // The rest of it is the message.  We'll URI-encode it so it comes out
    // as a single string without line breaks.
    String message = i.getStringExtra(EXTRA_MESSAGE);
    if (message != null)
        builder.append(Uri.encode(message));

    // Right... let's write it out.
    try {
        osw.write(builder.toString());
    } catch (IOException e) {
        // If we got an exception, we're in deep trouble.
        Log.e(DEBUG_TAG, "Exception when serializing an Intent!", e);
    }
}