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.hippo.nimingban.ui.GalleryActivity2.java

private boolean handlerIntent(Intent intent) {
    if (intent == null) {
        return false;
    }// ww w.  ja va  2s. c o m

    String action = intent.getAction();
    if (ACTION_SINGLE_IMAGE.equals(action)) {
        int site = intent.getIntExtra(KEY_SITE, -1);
        String id = intent.getStringExtra(KEY_ID);
        String image = intent.getStringExtra(KEY_IMAGE);
        if (Site.isValid(site) && id != null && image != null) {
            mGalleryAdapter = new SingleImageAdapter(Site.fromId(site), id, image);
            return true;
        }
    } else if (ACTION_IMAGE_FILE.equals(action)) {
        Uri fileUri = intent.getParcelableExtra(KEY_UNI_FILE_URI);
        UniFile file = UniFile.fromUri(this, fileUri);
        if (file != null && file.exists()) {
            mGalleryAdapter = new ImageFileAdapter(file);
            return true;
        }
    }
    return false;
}

From source file:com.owncloud.android.services.OperationsService.java

/**
 * Entry point to add a new operation to the queue of operations.
 *
 * New operations are added calling to startService(), resulting in a call to this method.
 * This ensures the service will keep on working although the caller activity goes away.
 *///  w  ww . j av a2 s .c  o  m
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    // WIP: for the moment, only SYNC_FOLDER is expected here;
    // the rest of the operations are requested through the Binder
    if (ACTION_SYNC_FOLDER.equals(intent.getAction())) {

        if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
            Log_OC.e(TAG, "Not enough information provided in intent");
            return START_NOT_STICKY;
        }
        Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);

        Pair<Account, String> itemSyncKey = new Pair<>(account, remotePath);

        Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
        if (itemToQueue != null) {
            mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation) itemToQueue.second);
            Message msg = mSyncFolderHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = itemSyncKey;
            mSyncFolderHandler.sendMessage(msg);
        }

    } else {
        Message msg = mOperationsHandler.obtainMessage();
        msg.arg1 = startId;
        mOperationsHandler.sendMessage(msg);
    }

    return START_NOT_STICKY;
}

From source file:com.kanedias.vanilla.audiotag.PluginService.java

/**
 * Write changes through SAF framework - the only way to do it in Android > 4.4 when working with SD card
 * @param activityResponse response with URI contained in. Can be null if tree permission is already given.
 *///from ww  w. j  a  v a 2 s  . c  om
private void persistThroughSaf(Intent activityResponse) {
    Uri safUri;
    if (mPrefs.contains(PREF_SDCARD_URI)) {
        // no sorcery can allow you to gain URI to the document representing file you've been provided with
        // you have to find it again using now Document API

        // /storage/volume/Music/some.mp3 will become [storage, volume, music, some.mp3]
        List<String> pathSegments = new ArrayList<>(
                Arrays.asList(mAudioFile.getFile().getAbsolutePath().split("/")));
        Uri allowedSdRoot = Uri.parse(mPrefs.getString(PREF_SDCARD_URI, ""));
        safUri = findInDocumentTree(DocumentFile.fromTreeUri(this, allowedSdRoot), pathSegments);
    } else {
        Intent originalSafResponse = activityResponse.getParcelableExtra(EXTRA_PARAM_SAF_P2P);
        safUri = originalSafResponse.getData();
    }

    if (safUri == null) {
        // nothing selected or invalid file?
        Toast.makeText(this, R.string.saf_nothing_selected, Toast.LENGTH_LONG).show();
        return;
    }

    try {
        // we don't have fd-related audiotagger write functions, have to use workaround
        // write audio file to temp cache dir
        // jaudiotagger can't work through file descriptor, sadly
        File original = mAudioFile.getFile();
        File temp = File.createTempFile("tmp-media", '.' + Utils.getExtension(original));
        Utils.copy(original, temp); // jtagger writes only header, we should copy the rest
        temp.deleteOnExit(); // in case of exception it will be deleted too
        mAudioFile.setFile(temp);
        AudioFileIO.write(mAudioFile);

        // retrieve FD from SAF URI
        ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(safUri, "rw");
        if (pfd == null) {
            // should not happen
            Log.e(LOG_TAG, "SAF provided incorrect URI!" + safUri);
            return;
        }

        // now read persisted data and write it to real FD provided by SAF
        FileInputStream fis = new FileInputStream(temp);
        byte[] audioContent = TagEditorUtils.readFully(fis);
        FileOutputStream fos = new FileOutputStream(pfd.getFileDescriptor());
        fos.write(audioContent);
        fos.close();

        // delete temporary file used
        temp.delete();

        // rescan original file
        MediaScannerConnection.scanFile(this, new String[] { original.getAbsolutePath() }, null, null);
        Toast.makeText(this, R.string.file_written_successfully, Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(this, getString(R.string.saf_write_error) + e.getLocalizedMessage(), Toast.LENGTH_LONG)
                .show();
        Log.e(LOG_TAG, "Failed to write to file descriptor provided by SAF!", e);
    }
}

From source file:com.google.android.apps.santatracker.presentquest.PlacesIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        switch (action) {
        case ACTION_SEARCH_NEARBY:
            // Don't allow more than X queries at once.
            if (mQueriesInProgress.get() >= MAX_QUERIES_IN_PROGRESS) {
                Log.d(TAG, "Dropping excess query");
                return;
            }//  w  ww  . ja  v a 2  s. c  o m

            // Mark query started
            mQueriesInProgress.incrementAndGet();

            if (mPreferences == null) {
                mPreferences = new PreferencesUtil(this);
            }
            if (mConfig == null) {
                mConfig = new Config();
            }

            // Perform query
            final LatLng center = intent.getParcelableExtra(EXTRA_LAT_LNG);
            final int radius = intent.getIntExtra(EXTRA_RADIUS, 0);
            getPlaceAndBroadcast(center, radius);

            // Mark query finished
            mQueriesInProgress.decrementAndGet();
            break;
        default:
            Log.w(TAG, "Unknown action: " + action);
        }
    }
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    String action = intent.getAction();

    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        // Get tag ID and turn into String
        byte[] tagIDbytes = tag.getId();
        tagID = bytesToHex(tagIDbytes);/* w  w w.j av a 2  s. c  om*/

        if (!tagID.equals("")) {
            // Dismiss the 'Scan NFC Tag' dialog and show the 'Set tag name' dialog
            dismissDialog(DIALOG_READ);

            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

            MainActivity.this.showDialog(DIALOG_SET_TAGNAME);
        }
    }
}

From source file:com.piusvelte.taplock.client.core.TapLockSettings.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();
    if (mInWriteMode) {
        if (intent != null) {
            String action = intent.getAction();
            if (mInWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
                    && intent.hasExtra(EXTRA_DEVICE_NAME)) {
                Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
                String name = intent.getStringExtra(EXTRA_DEVICE_NAME);
                if ((tag != null) && (name != null)) {
                    // write the device and address
                    String lang = "en";
                    // don't write the passphrase!
                    byte[] textBytes = name.getBytes();
                    byte[] langBytes = null;
                    int langLength = 0;
                    try {
                        langBytes = lang.getBytes("US-ASCII");
                        langLength = langBytes.length;
                    } catch (UnsupportedEncodingException e) {
                        Log.e(TAG, e.toString());
                    }//www.jav a  2  s. c o  m
                    int textLength = textBytes.length;
                    byte[] payload = new byte[1 + langLength + textLength];

                    // set status byte (see NDEF spec for actual bits)
                    payload[0] = (byte) langLength;

                    // copy langbytes and textbytes into payload
                    if (langBytes != null) {
                        System.arraycopy(langBytes, 0, payload, 1, langLength);
                    }
                    System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength);
                    NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT,
                            new byte[0], payload);
                    NdefMessage message = new NdefMessage(
                            new NdefRecord[] { record, NdefRecord.createApplicationRecord(getPackageName()) });
                    // Get an instance of Ndef for the tag.
                    Ndef ndef = Ndef.get(tag);
                    if (ndef != null) {
                        try {
                            ndef.connect();
                            if (ndef.isWritable()) {
                                ndef.writeNdefMessage(message);
                            }
                            ndef.close();
                            Toast.makeText(this, "tag written", Toast.LENGTH_LONG).show();
                        } catch (IOException e) {
                            Log.e(TAG, e.toString());
                        } catch (FormatException e) {
                            Log.e(TAG, e.toString());
                        }
                    } else {
                        NdefFormatable format = NdefFormatable.get(tag);
                        if (format != null) {
                            try {
                                format.connect();
                                format.format(message);
                                format.close();
                                Toast.makeText(getApplicationContext(), "tag written", Toast.LENGTH_LONG);
                            } catch (IOException e) {
                                Log.e(TAG, e.toString());
                            } catch (FormatException e) {
                                Log.e(TAG, e.toString());
                            }
                        }
                    }
                    mNfcAdapter.disableForegroundDispatch(this);
                }
            }
        }
        mInWriteMode = false;
    } else {
        SharedPreferences sp = getSharedPreferences(KEY_PREFS, MODE_PRIVATE);
        onSharedPreferenceChanged(sp, KEY_DEVICES);
        // check if configuring a widget
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                final String[] displayNames = TapLock.getDeviceNames(mDevices);
                final int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                        AppWidgetManager.INVALID_APPWIDGET_ID);
                if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
                    mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle("Select device for widget")
                            .setItems(displayNames, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    // set the successful widget result
                                    Intent resultValue = new Intent();
                                    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                                    setResult(RESULT_OK, resultValue);

                                    // broadcast the new widget to update
                                    JSONObject deviceJObj = mDevices.get(which);
                                    dialog.cancel();
                                    TapLockSettings.this.finish();
                                    try {
                                        sendBroadcast(TapLock
                                                .getPackageIntent(TapLockSettings.this, TapLockWidget.class)
                                                .setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
                                                .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
                                                .putExtra(EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME)));
                                    } catch (JSONException e) {
                                        Log.e(TAG, e.toString());
                                    }
                                }
                            }).create();
                    mDialog.show();
                }
            }
        }
        // start the service before binding so that the service stays around for faster future connections
        startService(TapLock.getPackageIntent(this, TapLockService.class));
        bindService(TapLock.getPackageIntent(this, TapLockService.class), this, BIND_AUTO_CREATE);

        int serverVersion = sp.getInt(KEY_SERVER_VERSION, 0);
        if (mShowTapLockSettingsInfo && (mDevices.size() == 0)) {
            if (serverVersion < SERVER_VERSION)
                sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit();
            mShowTapLockSettingsInfo = false;
            Intent i = TapLock.getPackageIntent(this, TapLockInfo.class);
            i.putExtra(EXTRA_INFO, getString(R.string.info_taplocksettings));
            startActivity(i);
        } else if (serverVersion < SERVER_VERSION) {
            // TapLockServer has been updated
            sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit();
            mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle(R.string.ttl_hasupdate)
                    .setMessage(R.string.msg_hasupdate)
                    .setNeutralButton(R.string.button_getserver, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();

                            mDialog = new AlertDialog.Builder(TapLockSettings.this)
                                    .setTitle(R.string.msg_pickinstaller)
                                    .setItems(R.array.installer_entries, new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.cancel();
                                            final String installer_file = getResources()
                                                    .getStringArray(R.array.installer_values)[which];

                                            mDialog = new AlertDialog.Builder(TapLockSettings.this)
                                                    .setTitle(R.string.msg_pickdownloader)
                                                    .setItems(R.array.download_entries,
                                                            new DialogInterface.OnClickListener() {

                                                                @Override
                                                                public void onClick(DialogInterface dialog,
                                                                        int which) {
                                                                    dialog.cancel();
                                                                    String action = getResources()
                                                                            .getStringArray(
                                                                                    R.array.download_values)[which];
                                                                    if (ACTION_DOWNLOAD_SDCARD.equals(action)
                                                                            && copyFileToSDCard(installer_file))
                                                                        Toast.makeText(TapLockSettings.this,
                                                                                "Done!", Toast.LENGTH_SHORT)
                                                                                .show();
                                                                    else if (ACTION_DOWNLOAD_EMAIL
                                                                            .equals(action)
                                                                            && copyFileToSDCard(
                                                                                    installer_file)) {
                                                                        Intent emailIntent = new Intent(
                                                                                android.content.Intent.ACTION_SEND);
                                                                        emailIntent.setType(
                                                                                "application/java-archive");
                                                                        emailIntent.putExtra(Intent.EXTRA_TEXT,
                                                                                getString(
                                                                                        R.string.email_instructions));
                                                                        emailIntent.putExtra(
                                                                                Intent.EXTRA_SUBJECT,
                                                                                getString(R.string.app_name));
                                                                        emailIntent.putExtra(
                                                                                Intent.EXTRA_STREAM,
                                                                                Uri.parse("file://"
                                                                                        + Environment
                                                                                                .getExternalStorageDirectory()
                                                                                                .getPath()
                                                                                        + "/"
                                                                                        + installer_file));
                                                                        startActivity(Intent.createChooser(
                                                                                emailIntent, getString(
                                                                                        R.string.button_getserver)));
                                                                    }
                                                                }

                                                            })
                                                    .create();
                                            mDialog.show();
                                        }
                                    }).create();
                            mDialog.show();
                        }
                    }).create();
            mDialog.show();
        }
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.RomDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rom_detail);

    Intent intent = getIntent();
    mRomInfo = intent.getParcelableExtra(EXTRA_ROM_INFO);
    mBootedRomInfo = intent.getParcelableExtra(EXTRA_BOOTED_ROM_INFO);
    mActiveRomId = intent.getStringExtra(EXTRA_ACTIVE_ROM_ID);

    if (savedInstanceState != null) {
        mTaskIdCacheWallpaper = savedInstanceState.getInt(EXTRA_STATE_TASK_ID_CACHE_WALLPAPER);
        mTaskIdSwitchRom = savedInstanceState.getInt(EXTRA_STATE_TASK_ID_SWITCH_ROM);
        mTaskIdSetKernel = savedInstanceState.getInt(EXTRA_STATE_TASK_ID_SET_KERNEL);
        mTaskIdUpdateRamdisk = savedInstanceState.getInt(EXTRA_STATE_TASK_ID_UPDATE_RAMDISK);
        mTaskIdWipeRom = savedInstanceState.getInt(EXTRA_STATE_TASK_ID_WIPE_ROM);
        mTaskIdCreateLauncher = savedInstanceState.getInt(EXTRA_STATE_TASK_ID_CREATE_LAUNCHER);
        mTaskIdGetRomDetails = savedInstanceState.getInt(EXTRA_STATE_TASK_ID_GET_ROM_DETAILS);
        mTaskIdsToRemove = savedInstanceState.getIntegerArrayList(EXTRA_STATE_TASK_IDS_TO_REMOVE);
        mResultIntent = savedInstanceState.getParcelable(EXTRA_STATE_RESULT_INTENT);
        setResult(RESULT_OK, mResultIntent);
        mBackupTargets = savedInstanceState.getStringArray(EXTRA_STATE_BACKUP_TARGETS);
    }/*ww  w  .  jav a 2 s.  c om*/

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mCoordinator = (CoordinatorLayout) findViewById(R.id.coordinator);
    mCollapsing = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    mWallpaper = (ImageView) findViewById(R.id.wallpaper);
    mFab = (FloatingActionButton) findViewById(R.id.fab);
    mRV = (RecyclerView) findViewById(R.id.main_rv);

    mFab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            switchRom(false);
        }
    });

    updateTitle();
    updateMbtoolStatus();

    initializeRecyclerView();
    populateRomCardItem();
    populateInfoItems();
    populateActionItems();
}

From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java

@Override
public void onNewIntent(Intent intent) {
    if (ACTION_CONNECT_INPUT.equals(intent.getAction())
            && (intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) == 0) {
        // We were the front most app and we got a new intent.
        // If screen saver is going, stop it.
        try {/*w ww. j ava 2 s. c om*/
            if (mDreamManager != null && mDreamManager.isDreaming()) {
                mDreamManager.awaken();
            }
        } catch (RemoteException e) {
            // Do nothing.
        }

        KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_PAIRING) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                onHwKeyEvent(false);
            } else if (event.getAction() == KeyEvent.ACTION_DOWN) {
                onHwKeyEvent(true);
            }
        }
    } else {
        setIntent(intent);
    }
}

From source file:ch.bfh.instacircle.NetworkActiveActivity.java

@Override
public void onNewIntent(Intent intent) {
    if (writeNfcEnabled) {
        // Handle the NFC part...

        SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0);
        String text = preferences.getString("SSID", "N/A") + "||" + preferences.getString("password", "N/A");

        // create a new NdefRecord
        NdefRecord record = createMimeRecord("application/ch.bfh.instacircle", text.getBytes());

        // create a new Android Application Record
        NdefRecord aar = NdefRecord.createApplicationRecord(getPackageName());

        // create a ndef message
        NdefMessage message = new NdefMessage(new NdefRecord[] { record, aar });

        // extract tag from the intent
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        // write the tag
        writeTag(tag, message);/*from w ww.  j  a v  a 2 s .  c o m*/

        // close the dialog
        writeNfcEnabled = false;
        writeNfcTagDialog.dismiss();
    }
}

From source file:com.aqtx.app.main.activity.MainActivity.java

private void onParseIntent() {
    Intent intent = getIntent();
    if (intent.hasExtra(NimIntent.EXTRA_NOTIFY_CONTENT)) {
        IMMessage message = (IMMessage) getIntent().getSerializableExtra(NimIntent.EXTRA_NOTIFY_CONTENT);
        switch (message.getSessionType()) {
        case P2P:
            SessionHelper.startP2PSession(this, message.getSessionId());
            break;
        case Team:
            SessionHelper.startTeamSession(this, message.getSessionId());
            break;
        default://from  w  w w. j  ava2s  . co m
            break;
        }
    } else if (intent.hasExtra(EXTRA_APP_QUIT)) {
        onLogout();
        return;
    } else if (intent.hasExtra(AVChatActivity.INTENT_ACTION_AVCHAT)) {
        if (AVChatProfile.getInstance().isAVChatting()) {
            Intent localIntent = new Intent();
            localIntent.setClass(this, AVChatActivity.class);
            startActivity(localIntent);
        }
    } else if (intent.hasExtra(Extras.EXTRA_JUMP_P2P)) {
        Intent data = intent.getParcelableExtra(Extras.EXTRA_DATA);
        String account = data.getStringExtra(Extras.EXTRA_ACCOUNT);
        if (!TextUtils.isEmpty(account)) {
            SessionHelper.startP2PSession(this, account);
        }
    }
}