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.lef.ibeacon.service.UpdateService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    mBluetoothDevice = intent.getParcelableExtra(EXTRA_DATA);
    return START_NOT_STICKY;
}

From source file:com.shafiq.myfeedle.core.StatusDialog.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();
    if (intent != null) {
        if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
            mFilePath = intent.getStringExtra(Widgets.INSTANT_UPLOAD);
            Log.d(TAG, "upload photo?" + mFilePath);
        } else {/*from w w w.  j ava2  s.  co  m*/
            mData = intent.getData();
            if (mData != null) {
                mData = intent.getData();
                if (intent.hasExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS))
                    mRect = intent.getParcelableExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS);
                else
                    mRect = intent.getSourceBounds();
                Log.d(TAG, "data:" + mData.toString());
                // need to use a thread here to avoid anr
                mLoadingDialog = new ProgressDialog(this);
                mLoadingDialog.setMessage(getString(R.string.status_loading));
                mLoadingDialog.setCancelable(true);
                mLoadingDialog.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface arg0) {
                        if (mStatusLoader != null)
                            mStatusLoader.cancel(true);
                        finish();
                    }
                });
                mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                        new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                finish();
                            }
                        });
                mLoadingDialog.show();
                mStatusLoader = new StatusLoader();
                mStatusLoader.execute();
            }
        }
    }
    if (mFilePath != null) {
        mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.uploadprompt)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivityForResult(
                                Myfeedle.getPackageIntent(getApplicationContext(), MyfeedleCreatePost.class)
                                        .putExtra(Widgets.INSTANT_UPLOAD, mFilePath),
                                RESULT_REFRESH);
                        dialog.dismiss();
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        StatusDialog.this.finish();
                    }
                }).create();
        mDialog.show();
    } else {
        // check if the dialog is still loading
        if (mFinish)
            finish();
        else if ((mLoadingDialog == null) || !mLoadingDialog.isShowing())
            showDialog();
    }
}

From source file:com.ximai.savingsmore.save.activity.BusinessMyCenterActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode != RESULT_OK) {
        return;/*from  w  ww. java2 s. com*/
    } else if (requestCode == PICK_FROM_CAMERA || requestCode == PICK_FROM_IMAGE) {

        Uri uri = null;
        if (null != intent && intent.getData() != null) {
            uri = intent.getData();
        } else {
            String fileName = PreferencesUtils.getString(this, "tempName");
            uri = Uri.fromFile(new File(FileSystem.getCachesDir(this, true).getAbsolutePath(), fileName));
        }

        if (uri != null) {
            cropImage(uri, CROP_PHOTO_CODE);
        }
    } else if (requestCode == CROP_PHOTO_CODE) {
        Uri photoUri = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
        if (isslinece) {
            MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), slience_image);
            zhizhao_path = photoUri.toString();
            try {
                upLoadImage(new File((new URI(photoUri.toString()))), "BusinessLicense");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        } else if (isZhengshu) {
            MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), zhengshu_iamge);
            xukezheng_path = photoUri.toString();
            try {
                upLoadImage(new File((new URI(photoUri.toString()))), "LicenseKey");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        } else if (isheadImage) {
            MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), head_image);
            tuoxiang_path = photoUri.toString();
            try {
                upLoadImage(new File((new URI(photoUri.toString()))), "Photo");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            //upLoadImage(new File((new URI(photoUri.toString()))), "Photo");
        } else if (isItem) {
            if (imagePath.size() + images.size() < 10) {
                shangpu_path.add(photoUri.toString());
                try {
                    upLoadImage(new File((new URI(photoUri.toString()))), "Seller");
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
                //imagePath.add(photoUri.getPath());
            } else {
                Toast.makeText(BusinessMyCenterActivity.this, "?9",
                        Toast.LENGTH_SHORT).show();
            }
        }
        //addImage(imagePath);
    }
}

From source file:com.android.managedprovisioning.DeviceOwnerProvisioningService.java

@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
    if (DEBUG)//from  w  ww  .  ja v a2 s.  c o  m
        ProvisionLogger.logd("Device owner provisioning service ONSTARTCOMMAND.");

    synchronized (this) { // Make operations on mProvisioningInFlight atomic.
        if (mProvisioningInFlight) {
            if (DEBUG)
                ProvisionLogger.logd("Provisioning already in flight.");

            sendProgressUpdateToActivity();

            // Send error message if currently in error state.
            if (mLastErrorMessage >= 0) {
                sendError();
            }

            // Send success if provisioning was successful.
            if (mDone) {
                onProvisioningSuccess();
            }
        } else {
            mProvisioningInFlight = true;
            if (DEBUG)
                ProvisionLogger.logd("First start of the service.");
            progressUpdate(R.string.progress_data_process);

            // Load the ProvisioningParams (from message in Intent).
            mParams = (ProvisioningParams) intent
                    .getParcelableExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS);

            // Do the work on a separate thread.
            new Thread(new Runnable() {
                public void run() {
                    initializeProvisioningEnvironment(mParams);
                    startDeviceOwnerProvisioning(mParams);
                }
            }).start();
        }
    }
    return START_NOT_STICKY;
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_details);

    setToolbar((Toolbar) findViewById(R.id.toolbar));

    if (getToolbar() != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.TRANSPARENT);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }/*ww  w  .j  av  a2 s  .c  o  m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getToolbar().setPadding(0, getStatusBarHeight(), 0, 0);
        }
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    final Intent intent = getIntent();
    String action = intent.getAction();

    if (Intent.ACTION_VIEW.equals(action)) {
        pageUri = Uri.parse(intent.getDataString());
        if ("wally".equalsIgnoreCase(pageUri.getScheme())) {
            pageUri = pageUri.buildUpon().scheme("http").build();
        }
    }

    setupViews();
    setupHandlers();

    Size size = new Size(16, 9);

    if (intent.hasExtra(INTENT_EXTRA_IMAGE)) {
        final Image image = intent.getParcelableExtra(INTENT_EXTRA_IMAGE);
        final Bitmap thumbBitmap = WallyApplication.getBitmapThumb();

        if (thumbBitmap != null) {

            size = fitToWidthAndKeepRatio(image.getWidth(), image.getHeight());

            imageSize = size;

            photoView.getLayoutParams().width = size.getWidth();
            photoView.getLayoutParams().height = size.getHeight();

            Bitmap blurBitMap;
            try {
                blurBitMap = Blur.apply(imageHolder.getContext(), thumbBitmap);
            } catch (ArrayIndexOutOfBoundsException e) {
                //Blur couldn't be applied. Show regular thumbnail instead.
                blurBitMap = thumbBitmap;
            }
            photoView.setImageBitmap(blurBitMap);
        }
    }
    setupPaddings(size, false);

    if (savedInstanceState == null) {
        getPage(pageUri.toString());
    } else if (savedInstanceState.containsKey(STATE_IMAGE_PAGE)) {
        imagePage = savedInstanceState.getParcelable(STATE_IMAGE_PAGE);
    }

    if (imagePage != null) {
        Message msgObj = uiHandler.obtainMessage();
        msgObj.what = MSG_PAGE_FETCHED;
        msgObj.obj = imagePage;
        uiHandler.sendMessage(msgObj);
    } else {
        getPage(pageUri.toString());
    }

}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == RequestCode.SEARCH.value) {
        Log.v(LOG_TAG, "-> onActivityResult -> " + RequestCode.SEARCH);

        if (resultCode == RESULT_CANCELED)
            return;

        searchAdapterDataBundle = data.getBundleExtra(SearchAdapter.DATA_BUNDLE);
        searchQuery = data.getCharSequenceExtra(SearchActivity.BUNDLE_SAVE_SEARCH_QUERY);

        if (resultCode == SearchActivity.ResultCode.ITEM_SELECTED.getValue()) {

            searchItem = data.getParcelableExtra(EXTRA_SEARCH_ITEM);
            // In case if SearchActivity is recreated due to screen rotation then FolioActivity
            // will also be recreated, so mFolioPageViewPager might be null.
            if (mFolioPageViewPager == null)
                return;
            currentChapterIndex = getChapterIndex(Constants.HREF, searchItem.getHref());
            mFolioPageViewPager.setCurrentItem(currentChapterIndex);
            FolioPageFragment folioPageFragment = getCurrentFragment();
            if (folioPageFragment == null)
                return;
            folioPageFragment.highlightSearchItem(searchItem);
            searchItem = null;//from  w  w w . java 2  s.c  o  m
        }

    } else if (requestCode == RequestCode.CONTENT_HIGHLIGHT.value && resultCode == RESULT_OK
            && data.hasExtra(TYPE)) {

        String type = data.getStringExtra(TYPE);

        if (type.equals(CHAPTER_SELECTED)) {
            goToChapter(data.getStringExtra(SELECTED_CHAPTER_POSITION));

        } else if (type.equals(HIGHLIGHT_SELECTED)) {
            HighlightImpl highlightImpl = data.getParcelableExtra(HIGHLIGHT_ITEM);
            currentChapterIndex = highlightImpl.getPageNumber();
            mFolioPageViewPager.setCurrentItem(currentChapterIndex);
            FolioPageFragment folioPageFragment = getCurrentFragment();
            if (folioPageFragment == null)
                return;
            folioPageFragment.scrollToHighlightId(highlightImpl.getRangy());
        }
    }
}

From source file:com.markupartist.sthlmtraveling.RoutesActivity.java

/**
 * This method is called when the sending activity has finished, with the
 * result it supplied.//from   w  ww  .j a va 2  s .  c  o m
 * 
 * @param requestCode The original request code as given to startActivity().
 * @param resultCode From sending activity as per setResult().
 * @param data From sending activity as per setResult().
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_CHANGE_TIME:
        if (resultCode == RESULT_CANCELED) {
            Log.d(TAG, "Change time activity cancelled.");
        } else {
            mJourneyQuery = data.getParcelableExtra(EXTRA_JOURNEY_QUERY);

            HashMap<String, String> item = mDateAdapterData.get(0);
            item.put("title", buildDateString());

            mSearchRoutesTask = new SearchRoutesTask();
            mSearchRoutesTask.execute(mJourneyQuery);
        }
        break;
    case REQUEST_CODE_POINT_ON_MAP_START:
        if (resultCode == RESULT_CANCELED) {
            Log.d(TAG, "action canceled");
            finish();
            return;
        } else {
            Site startPoint = data.getParcelableExtra(PointOnMapActivity.EXTRA_STOP);
            Log.d(TAG, "Got Stop " + startPoint);

            mJourneyQuery.origin.name = Planner.Location.TYPE_MY_LOCATION;
            mJourneyQuery.origin.latitude = (int) (startPoint.getLocation().getLatitude() * 1E6);
            mJourneyQuery.origin.longitude = (int) (startPoint.getLocation().getLongitude() * 1E6);

            mSearchRoutesTask = new SearchRoutesTask();
            mSearchRoutesTask.execute(mJourneyQuery);

            // TODO: Is this call really needed?
            updateStartAndEndPointViews(mJourneyQuery);
        }
        break;
    case REQUEST_CODE_POINT_ON_MAP_END:
        if (resultCode == RESULT_CANCELED) {
            Log.d(TAG, "action canceled");
            finish();
            return;
        } else {
            Site endPoint = data.getParcelableExtra(PointOnMapActivity.EXTRA_STOP);
            Log.d(TAG, "Got Stop " + endPoint);

            mJourneyQuery.destination.name = Planner.Location.TYPE_MY_LOCATION;
            mJourneyQuery.destination.latitude = (int) (endPoint.getLocation().getLatitude() * 1E6);
            mJourneyQuery.destination.longitude = (int) (endPoint.getLocation().getLongitude() * 1E6);

            mSearchRoutesTask = new SearchRoutesTask();
            mSearchRoutesTask.execute(mJourneyQuery);

            // TODO: Is this call really needed?
            updateStartAndEndPointViews(mJourneyQuery);
        }

        break;
    }
}

From source file:com.linute.linute.API.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM Bundle received.//from  ww  w. j a v  a 2 s .  com
 */
private void sendNotification(Bundle data, String action) {

    Intent intent = buildIntent(data, action);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent,
            PendingIntent.FLAG_ONE_SHOT);

    //Log.d(TAG, data.toString());

    String message = data.getString("message");

    //int type = gettNotificationType(data.getString("action"));
    //String name = data.getString("ownerFullName");
    boolean isAnon = "1".equals(data.getString("privacy"));
    String profileImage = null;
    switch (action) {
    case "messager":
        try {
            JSONObject image = new JSONObject(data.getString("roomProfileImage"));
            profileImage = image.getString("original");
        } catch (JSONException | NullPointerException e) {
        }
        break;
    default:
        profileImage = data.getString("ownerProfileImage");
        profileImage = (isAnon ? Utils.getAnonImageUrl(String.valueOf(profileImage))
                : Utils.getImageUrlOfUser(String.valueOf(profileImage)));
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    ChatRoom chatRoom = (ChatRoom) intent.getParcelableExtra("chatRoom");
    String title = chatRoom != null ? chatRoom.getRoomName() : "Tapt";
    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_untitled_4_01).setColor(Color.BLACK).setContentTitle(title)
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    if (profileImage != null) {
        File image = null;
        try {
            image = Glide.with(this).load(profileImage).downloadOnly(256, 256).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        if (image != null) {
            /*ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
            ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
            manager.getMemoryInfo(info);*/

            notificationBuilder.setLargeIcon(getCircleBitmap(image));

        }
    }

    BigInteger notificationId;

    Object ownerId = data.get("room");
    Object eventId = data.get("event");
    if (eventId != null) {
        notificationId = new BigInteger(String.valueOf(eventId), 16);
    } else if (ownerId != null) {
        notificationId = new BigInteger(String.valueOf(ownerId), 16);
    } else {
        notificationId = BigInteger.ZERO;
    }

    final int notifId = notificationId.intValue();
    Notification notifications = notificationBuilder.build();
    NotificationManagerCompat.from(this).notify(notificationId.intValue(), notifications);
}

From source file:com.nextgis.firereporter.GetFiresService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (intent == null)
        return START_REDELIVER_INTENT;

    int nCommnad = intent.getIntExtra(COMMAND, SERVICE_START);

    SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS);
    long nUpdateInterval = prefs.getLong(SettingsActivity.KEY_PREF_INTERVAL + "_long",
            30 * DateUtils.MINUTE_IN_MILLIS); //15
    boolean bEnergyEconomy = prefs.getBoolean(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE, true);

    Log.d(MainActivity.TAG, "Received intent - id " + startId + ": " + intent + ", command:" + nCommnad);

    if ((nCommnad & SERVICE_START) != 0) {
        mUserNasaReceiver = intent.getParcelableExtra(RECEIVER);
        if (mUserNasaReceiver != null) {
            mnFilter = intent.getIntExtra(SOURCE, MainActivity.SRC_NASA | MainActivity.SRC_USER);

            if (mnCurrentExec < 1) {
                mUserNasaReceiver.send(SERVICE_START, new Bundle());
            }/*w  w  w .j  a v a  2 s .  com*/
            Log.d(MainActivity.TAG, "GetFiresService service started");
            if ((mnFilter & MainActivity.SRC_NASA) != 0) {
                mnCurrentExec++;
                GetNasaData(false);
            }

            if ((mnFilter & MainActivity.SRC_USER) != 0) {
                mnCurrentExec++;
                GetUserData(false);
            }
        }
        // plan next start
        ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy);
    }

    if ((nCommnad & SERVICE_SCANEXSTART) != 0) {
        mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX);
        if (mScanexReceiver != null) {
            if (mnCurrentExec < 1) {
                mScanexReceiver.send(SERVICE_SCANEXSTART, new Bundle());
            }
            Log.d(MainActivity.TAG, "GetFiresService service started");
            GetScanexData(false);
        }
        // plan next start
        ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy);

    }

    if ((nCommnad & SERVICE_STOP) != 0) {
        Log.d(MainActivity.TAG, "GetFiresService service stopped");
        ScheduleNextUpdate(this, SERVICE_DESTROY, 150, true);
        stopSelf();
    }

    if ((nCommnad & SERVICE_DESTROY) != 0) {
        stopSelf();
    }

    if ((nCommnad & SERVICE_DATA) != 0) {
        mUserNasaReceiver = intent.getParcelableExtra(RECEIVER);
        for (FireItem item : mmoFires.values()) {
            SendItem(item);
        }
    }

    if ((nCommnad & SERVICE_SCANEXDATA) != 0) {
        mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX);
        for (ScanexSubscriptionItem Item : mmoSubscriptions.values()) {
            SendScanexItem(Item);
        }
    }

    if ((nCommnad & SERVICE_SCANEXDATAUPDATE) != 0) {
        long nSubscirbeId = intent.getLongExtra(SUBSCRIPTION_ID, -1);
        long nNotificationId = intent.getLongExtra(NOTIFICATION_ID, -1);
        ScanexSubscriptionItem subscribe = mmoSubscriptions.get(nSubscirbeId);
        if (subscribe != null) {
            ScanexNotificationItem notification = subscribe.GetItems().get(nNotificationId);
            if (notification != null) {
                notification.setWatched(true);
            }
        }
    }

    if ((nCommnad & SERVICE_NOTIFY_DISMISSED) != 0) {
        nUserCount = 0;
        nNasaCount = 0;
        nScanexCount = 0;

        mInboxStyle = new NotificationCompat.InboxStyle();
        mInboxStyle.setBigContentTitle(getString(R.string.stNewFireNotificationDetailes));

        ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy);
    }

    return START_REDELIVER_INTENT;
}