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.nfc.gemkey.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    if (DEBUG)/*from  w  ww.  j  a  v  a2 s.c om*/
        Log.d(TAG, "onNewIntent");

    final String action = intent.getAction();
    if (action.equals(NfcAdapter.ACTION_TAG_DISCOVERED)) {
        if (DEBUG)
            Log.i(TAG, "Discovered tag with intent: " + action);
        Tag myTag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        String nfc_tag_id = bytesToHexString(myTag.getId()).toUpperCase();
        tagId.setText("Tag ID : " + nfc_tag_id);

        if (mCheckTagInfoThread != null && mCheckTagInfoThread.isAlive()) {
            mCheckTagInfoThread.terminate();
            mCheckTagInfoThread = null;
        }
        mCheckTagInfoThread = new CheckTagInfoThread(nfc_tag_id);
        mCheckTagInfoThread.start();
    }
}

From source file:com.dsi.ant.antplus.pluginsampler.bloodpressure.Activity_BloodPressureSampler.java

private void resetPcc() {
    //Release the old access if it exists
    if (releaseHandle != null) {
        releaseHandle.close();/*from ww  w  .  j av  a2  s  .  co m*/
    }

    clearLayoutList();

    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 = AntPlusBloodPressurePcc.requestAccess(this, result.getAntDeviceNumber(), 0,
                mResultReceiver, mDeviceStateChangeReceiver);
    } else {
        // starts the plugins UI search
        releaseHandle = AntPlusBloodPressurePcc.requestAccess(this, this, mResultReceiver,
                mDeviceStateChangeReceiver);
    }
}

From source file:com.hippo.ehviewer.download.DownloadService.java

private void handleIntent(Intent intent) {
    String action = null;// w w  w  . j  av  a2  s.  co  m
    if (intent != null) {
        action = intent.getAction();
    }

    if (ACTION_START.equals(action)) {
        GalleryInfo gi = intent.getParcelableExtra(KEY_GALLERY_INFO);
        String label = intent.getStringExtra(KEY_LABEL);
        if (gi != null && mDownloadManager != null) {
            mDownloadManager.startDownload(gi, label);
        }
    } else if (ACTION_START_RANGE.equals(action)) {
        LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
        if (gidList != null && mDownloadManager != null) {
            mDownloadManager.startRangeDownload(gidList);
        }
    } else if (ACTION_START_ALL.equals(action)) {
        if (mDownloadManager != null) {
            mDownloadManager.startAllDownload();
        }
    } else if (ACTION_STOP.equals(action)) {
        long gid = intent.getLongExtra(KEY_GID, -1);
        if (gid != -1 && mDownloadManager != null) {
            mDownloadManager.stopDownload(gid);
        }
    } else if (ACTION_STOP_CURRENT.equals(action)) {
        if (mDownloadManager != null) {
            mDownloadManager.stopCurrentDownload();
        }
    } else if (ACTION_STOP_RANGE.equals(action)) {
        LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
        if (gidList != null && mDownloadManager != null) {
            mDownloadManager.stopRangeDownload(gidList);
        }
    } else if (ACTION_STOP_ALL.equals(action)) {
        if (mDownloadManager != null) {
            mDownloadManager.stopAllDownload();
        }
    } else if (ACTION_DELETE.equals(action)) {
        long gid = intent.getLongExtra(KEY_GID, -1);
        if (gid != -1 && mDownloadManager != null) {
            mDownloadManager.deleteDownload(gid);
        }
    } else if (ACTION_DELETE_RANGE.equals(action)) {
        LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
        if (gidList != null && mDownloadManager != null) {
            mDownloadManager.deleteRangeDownload(gidList);
        }
    } else if (ACTION_CLEAR.equals(action)) {
        clear();
    }

    checkStopSelf();
}

From source file:com.keithandthegirl.services.download.DownloadService.java

@TargetApi(8)
@Override//w w w.j  av  a 2 s .  c  om
protected void onHandleIntent(Intent requestIntent) {
    Log.v(TAG, "onHandleIntent : enter");

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mOriginalRequestIntent = requestIntent;

    Resource resourceType = Resource.valueOf(requestIntent.getStringExtra(RESOURCE_TYPE_EXTRA));
    mCallback = requestIntent.getParcelableExtra(SERVICE_CALLBACK);

    Uri data = requestIntent.getData();
    String urlPath = requestIntent.getStringExtra("urlpath");
    String directory = requestIntent.getStringExtra("directory");

    String filename = data.getLastPathSegment();

    File root;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        switch (resourceType) {
        case MP3:
            root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS);

            break;
        case MP4:
            root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);

            break;
        case M4V:
            root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);

            break;
        case JPG:
            root = getExternalCacheDir();
            filename = requestIntent.getLongExtra("id", -1) + ".jpg";

            break;
        default:
            root = getExternalCacheDir();

            break;
        }
    } else {
        root = Environment.getExternalStorageDirectory();
    }

    File outputDir = new File(root, directory);
    outputDir.mkdirs();

    File output = new File(outputDir, filename);
    if (output.exists()) {
        result = FragmentActivity.RESULT_OK;

        mCallback.send(result, getOriginalIntentBundle());

        Log.v(TAG, "onHandleIntent : exit, image exists");
        return;
    }

    switch (resourceType) {
    case MP3:
        Log.v(TAG, "onHandleIntent : saving mp3");

        savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath,
                output);
        mCallback.send(result, getOriginalIntentBundle());

        break;

    case MP4:
        Log.v(TAG, "onHandleIntent : saving mp4");

        savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath,
                output);
        mCallback.send(result, getOriginalIntentBundle());

        break;

    case M4V:
        Log.v(TAG, "onHandleIntent : saving m4v");

        savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath,
                output);
        mCallback.send(result, getOriginalIntentBundle());

        break;

    case JPG:
        Log.v(TAG, "onHandleIntent : saving jpg");

        saveBitmap(requestIntent.getStringExtra("filename"), urlPath, output);
        mCallback.send(result, getOriginalIntentBundle());

        break;
    default:
        Log.w(TAG, "onHandleIntent : unknown extension '" + resourceType.getExtension() + "'");

        mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
        break;
    }

    Log.v(TAG, "onHandleIntent : exit");
}

From source file:jp.co.brilliantservice.android.writertdtext.HomeActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String action = intent.getAction();
    if (TextUtils.isEmpty(action))
        return;//www .j av a 2s  .  c  o  m

    if (!action.equals(NfcAdapter.ACTION_TECH_DISCOVERED))
        return;

    // NdefMessage?
    String languageCode = "en";
    String text = String.format("Hello, World.(%s)", DATE_FORMAT.format(System.currentTimeMillis()));
    NdefMessage message = createTextMessage(text, languageCode);

    // ??????????
    Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    List<String> techList = Arrays.asList(tag.getTechList());
    if (techList.contains(Ndef.class.getName())) {
        Ndef ndef = Ndef.get(tag);
        writeNdefToNdefTag(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEF tag", Toast.LENGTH_SHORT).show();
    } else if (techList.contains(NdefFormatable.class.getName())) {
        NdefFormatable ndef = NdefFormatable.get(tag);
        writeNdefToNdefFormatable(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEFFormatable tag", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(), "NDEF Not Supported", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.dycody.android.idealnote.MainActivity.java

private void handleIntents() {
    Intent i = getIntent();

    if (i.getAction() == null)
        return;/*  w w  w.  java 2s . c o  m*/

    if (Constants.ACTION_RESTART_APP.equals(i.getAction())) {
        SystemHelper.restartApp(getApplicationContext(), MainActivity.class);
    }

    if (receivedIntent(i)) {
        Note note = i.getParcelableExtra(Constants.INTENT_NOTE);
        if (note == null) {
            note = DbHelper.getInstance().getNote(i.getIntExtra(Constants.INTENT_KEY, 0));
        }
        // Checks if the same note is already opened to avoid to open again
        if (note != null && noteAlreadyOpened(note)) {
            return;
        }
        // Empty note instantiation
        if (note == null) {
            note = new Note();
        }
        switchToDetail(note);
        return;
    }

    if (Constants.ACTION_SEND_AND_EXIT.equals(i.getAction())) {
        saveAndExit(i);
        return;
    }

    // Tag search
    if (Intent.ACTION_VIEW.equals(i.getAction())) {
        switchToList();
        return;
    }

    // Home launcher shortcut widget
    if (Constants.ACTION_SHORTCUT_WIDGET.equals(i.getAction())) {
        switchToDetail(new Note());
        return;
    }
}

From source file:com.github.jobs.ui.activity.EditTemplateActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != Activity.RESULT_OK) {
        return;/* w w  w . j av  a  2  s . c  o m*/
    }
    switch (requestCode) {
    case SOUserPickerActivity.REQUEST_CODE:
        if (data == null) {
            // meh... there was no data
            return;
        }
        Parcelable userParcel = data.getParcelableExtra(SOUserPickerActivity.EXTRA_USER);
        if (userParcel instanceof SOUser) {
            SOUser soUser = (SOUser) userParcel;
            // create new cover letter service
            TemplateService soService = new TemplateService();
            soService.setType(StackOverflowService.TYPE);
            soService.setData(soUser.getLink());

            // push cover letter to the fragment holding template information
            if (!addTemplateService(soService))
                return;

            // add the website service if possible
            if (soUser.getWebsiteUrl() != null) {
                TemplateService webService = new TemplateService();
                webService.setType(WebsiteService.TYPE);
                webService.setData(soUser.getWebsiteUrl());
                if (!addTemplateService(webService))
                    return;
            }
            Toast.makeText(this, getString(R.string.so_link_added), Toast.LENGTH_LONG).show();
        }
        break;
    case ServiceChooserDialog.REQUEST_CODE:
        int serviceId = data.getIntExtra(ServiceChooserDialog.RESULT_SERVICE_ID, -1);
        if (serviceId == -1) {
            Parcelable[] templateServices = data.getParcelableArrayExtra(ServiceChooserDialog.RESULT_SERVICES);
            if (templateServices != null) {
                for (Parcelable templateService : templateServices) {
                    addTemplateService((TemplateService) templateService);
                }
            }
        } else {
            if (serviceId == R.id.service_so) {
                Intent intent = new Intent(this, SOUserPickerActivity.class);
                startActivityForResult(intent, SOUserPickerActivity.REQUEST_CODE);
            } else {
                TemplateService templateService = getTemplateFromResult(serviceId, data);
                if (templateService != null) {
                    addTemplateService(templateService);
                }
            }
        }
        break;
    }
}

From source file:com.money.manager.ex.sync.SyncService.java

@Override
protected void onHandleWork(Intent intent) {
    String action = intent != null ? intent.getAction() : "null";
    Timber.d("Running sync service: %s", action);
    sendStartEvent();//from  www . j av  a2s  .  c o m

    // Check if there is a messenger. Used to send the messages back.
    if (intent.getExtras().containsKey(SyncService.INTENT_EXTRA_MESSENGER)) {
        mOutMessenger = intent.getParcelableExtra(SyncService.INTENT_EXTRA_MESSENGER);
    }

    // check if the device is online.
    NetworkUtils network = new NetworkUtils(getApplicationContext());
    if (!network.isOnline()) {
        Timber.i("Can't sync. Device not online.");
        sendMessage(SyncServiceMessage.NOT_ON_WIFI);
        sendStopEvent();
        return;
    }

    SyncManager sync = new SyncManager(getApplicationContext());

    String localFilename = intent.getStringExtra(SyncConstants.INTENT_EXTRA_LOCAL_FILE);
    String remoteFilename = intent.getStringExtra(SyncConstants.INTENT_EXTRA_REMOTE_FILE);
    // check if file is correct
    if (TextUtils.isEmpty(localFilename) || TextUtils.isEmpty(remoteFilename)) {
        sendStopEvent();
        return;
    }

    CloudMetaData remoteFile = sync.loadMetadata(remoteFilename);
    if (remoteFile == null) {
        sendMessage(SyncServiceMessage.ERROR);
        sendStopEvent();
        return;
    }
    File localFile = new File(localFilename);

    // todo: modify this part after db initial upload has been implemented.
    //        if (remoteFile == null) {
    //            // file not found on remote server.
    //            if (intent.getAction().equals(SyncConstants.INTENT_ACTION_UPLOAD)) {
    //                // Create a new entry in the root?
    //                Log.w(LOGCAT, "remoteFile is null. SyncService forcing creation of the new remote file.");
    //                remoteFile = new CloudMetaData();
    //                remoteFile.setPath(remoteFilename);
    //            } else {
    //                Timber.e("remoteFile is null. SyncService.onHandleIntent premature exit.");
    //                sendMessage(SyncServiceMessage.ERROR);
    //                return;
    //            }
    //        }

    // check if name is same
    if (!localFile.getName().toLowerCase().equals(remoteFile.getName().toLowerCase())) {
        Timber.w("Local filename different from the remote!");
        sendMessage(SyncServiceMessage.ERROR);
        sendStopEvent();
        return;
    }

    // Execute action.
    switch (action) {
    case SyncConstants.INTENT_ACTION_DOWNLOAD:
        triggerDownload(localFile, remoteFile);
        break;
    case SyncConstants.INTENT_ACTION_UPLOAD:
        triggerUpload(localFile, remoteFile);
        break;
    case SyncConstants.INTENT_ACTION_SYNC:
    default:
        triggerSync(localFile, remoteFile);
        break;
    }
}

From source file:my.home.lehome.service.SendMsgIntentService.java

private void preparePengindCommand(Intent intent) {
    Messenger messenger;/*from   w ww .  jav a 2 s.c  o  m*/
    if (intent.hasExtra("messenger"))
        messenger = (Messenger) intent.getExtras().get("messenger");
    else
        messenger = null;
    Message repMsg = Message.obtain();
    repMsg.what = MSG_BEGIN_SENDING;

    boolean isSysCmd = intent.getBooleanExtra("isSysCmd", false);
    if (isSysCmd) {
        Log.d(TAG, "sys cmd item");
        return;
    }

    ChatItem item = intent.getParcelableExtra("update");
    if (item == null) {
        item = new ChatItem();
        item.setContent(intent.getStringExtra("cmd"));
        item.setType(ChatItemConstants.TYPE_CLIENT);
        item.setState(Constants.CHATITEM_STATE_ERROR); // set ERROR
        item.setDate(new Date());
        DBStaticManager.addChatItem(getApplicationContext(), item);
    }
    item.setState(Constants.CHATITEM_STATE_PENDING);

    Log.d(TAG, "enqueue item: \n" + item);
    Bundle bundle = new Bundle();
    bundle.putBoolean("update", intent.hasExtra("update"));
    bundle.putParcelable("item", item);
    if (messenger != null) {
        repMsg.setData(bundle);
        try {
            messenger.send(repMsg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    } else {
        Log.d(TAG, "messager is null, send broadcast instead:" + ACTION_SEND_MSG_BEGIN);
        Intent newIntent = new Intent(ACTION_SEND_MSG_BEGIN);
        newIntent.putExtras(bundle);
        sendBroadcast(newIntent);
    }

    intent.putExtra("pass_item", item);
}

From source file:net.niyonkuru.koodroid.service.SessionService.java

@Override
public void onHandleIntent(Intent intent) {
    if (DEBUG)/*from w w w  . jav  a 2s.c  o  m*/
        Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    int request = intent.getIntExtra(EXTRA_REQUEST, REQUEST_LOGIN);
    if (request == REQUEST_LOGOUT) {
        logout();
        return;
    }

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);

    final String email = intent.getStringExtra(EXTRA_EMAIL);
    final String password = intent.getStringExtra(EXTRA_PASSWORD);
    boolean broadcast = intent.getBooleanExtra(EXTRA_BROADCAST, false);

    /* totally ignore this request until full credentials are provided */
    if (email == null || password == null)
        return;

    final long startLogin = System.currentTimeMillis();
    final long lastLogin = mSettings.lastLogin();

    /* if the last successful login is within the last 15 minutes */
    if (startLogin - lastLogin <= DateUtils.MINUTE_IN_MILLIS * 15) {

        /* do a credentials check again the local data store */
        if (email.equals(mSettings.email()) && password.equals(mSettings.password())) {
            if (broadcast)
                IntentUtils.callWidget(this, LOGIN_FINISHED);
            announce(receiver, STATUS_FINISHED);
            return;
        }
    }

    try {
        if (NetworkUtils.isConnected(this)) {
            /* announce to the caller that we are now running */
            announce(receiver, STATUS_RUNNING);

        } else
            throw new ServiceException(getString(R.string.error_network_down));

        if (mSettings.email() == null) {
            /* this is likely a new user */
            Crittercism.leaveBreadcrumb(TAG + ": first_time_login");
        }

        login(email, password);
        saveCookies();

        if (DEBUG)
            Log.d(TAG, "login took " + (System.currentTimeMillis() - startLogin) + "ms");

    } catch (IOException e) {
        if (DEBUG)
            Log.e(TAG, "Problem while logging in", e);

        /* if the exception was simply from an abort */
        if (mPostRequest != null && mPostRequest.isAborted())
            return;

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
        return; /* do not announce success below */
    }

    if (broadcast)
        IntentUtils.callWidget(this, LOGIN_FINISHED);
    announce(receiver, STATUS_FINISHED);
}