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:fr.openbike.android.service.SyncService.java

@SuppressWarnings("unchecked")
@Override/*from  w  w w .  j  a va 2  s  . c o m*/
protected void onHandleIntent(Intent intent) {
    NetworkInfo activeNetwork = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    Bundle bundle = new Bundle();
    int status = STATUS_ERROR;
    if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
        bundle = new Bundle();
        bundle.putString(Intent.EXTRA_TEXT, "No network connectivity");
        receiver.send(STATUS_ERROR, bundle);
        return;
    }
    String action = intent.getAction();
    try {
        if (ACTION_SYNC.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor.executeGet(
                    mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "") + "/v2/stations",
                    new RemoteStationsSyncHandler(
                            prefs.getLong(AbstractPreferencesActivity.STATIONS_VERSION, 0)),
                    this);
            if (result == null) {
                // Need stations update
                action = ACTION_UPDATE;
            } else {
                String message = (String) result;
                status = STATUS_SYNC_STATIONS_FINISHED;
                if (!"".equals(message)) {
                    bundle.putString(EXTRA_RESULT, message);
                }
                prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis())
                        .commit();
            }
        }
        if (ACTION_UPDATE.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_UPDATE_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor
                    .executeGet(mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "")
                            + "/v2/stations/list", new RemoteStationsUpdateHandler(), this);
            status = STATUS_UPDATE_STATIONS_FINISHED;
            if (result != null) {
                bundle.putString(EXTRA_RESULT, (String) result);
            }
            prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis()).commit();
        }
        if (ACTION_CHOOSE_NETWORK.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_NETWORKS, Bundle.EMPTY);
                bundle = new Bundle();
                bundle.putParcelableArrayList(EXTRA_RESULT, (ArrayList<Network>) mRemoteExecutor
                        .executeGet(NETWORKS_URL, new RemoteNetworksHandler(), this));
                status = STATUS_SYNC_NETWORKS_FINISHED;
            }
        }
        if (receiver != null) {
            receiver.send(status, bundle);
        }
    } catch (HandlerException e) {
        if (receiver != null) {
            // Pass back error to surface listener
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    } catch (Exception e) {
        if (receiver != null) {
            // Pass back error to surface listener
            e.printStackTrace();
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, "Une erreur est survenue. Veuillez ressayer.");
            receiver.send(STATUS_ERROR, bundle);
        }
    }
}

From source file:com.packpublishing.asynchronousandroid.chapter5.CountMsgsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {

    String phoneNumber = intent.getStringExtra(NUMBER_KEY);
    Cursor cursor = countMsgsFrom(phoneNumber);
    int numberOfMsgs = cursor.getCount();

    Log.i("CountMsgsIntentService", "Number of messages found : " + numberOfMsgs);

    notifyUser(phoneNumber, numberOfMsgs);

    try {//  w w w .  java  2 s.c o  m
        Intent result = new Intent();
        result.putExtra(RESULT, numberOfMsgs);
        PendingIntent reply = intent.getParcelableExtra(PENDING_RESULT);
        reply.send(this, RESULT_CODE, result);
    } catch (PendingIntent.CanceledException exc) {
        Log.e("CountMsgsIntentService", "reply cancelled", exc);
    }
}

From source file:com.mattprecious.notisync.profile.SecondaryCustomProfileActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_RINGTONE_PICKER:
        if (resultCode == RESULT_OK) {
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            if (uri == null) {
                profile.setRingtone(null);
            } else {
                profile.setRingtone(uri.toString());
            }//from ww  w  .j ava 2 s  .c  om

            updateRingtoneSelector();
        }
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;// w ww  .  ja  va2 s .c o  m
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.meetingninja.csse.agenda.AgendaActivity.java

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

    System.out.println("Arrived here");
    if (resultCode == Activity.RESULT_OK) {
        System.out.println("Arrived here");
        if (requestCode == 6) {
        } else if (requestCode == 7) {
            System.out.println("Arrived here");
            Task t = data.getParcelableExtra(Keys.Task.PARCEL);
            t.setCreatedBy(SessionManager.getInstance().getUserID());
            CreateTaskTask creator = new CreateTaskTask(null);
            creator.createTask(t);/*www  .  j  a va 2  s  . c om*/
        }
    }
}

From source file:com.llf.android.launcher3.InstallShortcutReceiver.java

@Override
public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/* w  w w  .ja va  2s  .c o  m*/
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/* w  w  w  .  j  a va 2s .co  m*/
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.nbplus.vbroadlauncher.service.BroadcastChatHeadService.java

private void createBroadcastChatHead(Intent intent) {
    if (intent == null) {
        return;//from  w  ww .j  ava  2  s  . c om
    }

    mBroadcastData = intent.getParcelableExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA);
    if (mBroadcastData == null) {
        Log.d(TAG, "Broadcast data is not found!!!");
        return;
    }
    long mBroadcastIndex = intent.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1);
    String pushType = mBroadcastData.getServiceType();
    if (!Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST.equals(pushType)
            && !Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(pushType)
            && !Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(pushType)) {
        Log.d(TAG, "This is not broadcast push type !!!");
        return;
    }
    if (mIsPlaying && mChatHead != null) {
        removeChatHead(true);
    }

    mIsPlaying = true;

    int layout = -1;
    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(pushType)) {
        layout = R.layout.fragment_text_broadcast;
    } else {
        layout = R.layout.fragment_audio_broadcast;
    }
    mChatHead = inflater.inflate(layout, null);

    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) {
        // ?
        mTextView = (TextView) mChatHead.findViewById(R.id.broadcast_text);
        mTextView.setText(mBroadcastData.getMessage());
        mTextView.setVerticalScrollBarEnabled(true);
        mTextView.setHorizontalScrollBarEnabled(false);
        mTextView.setMovementMethod(new ScrollingMovementMethod());

        mText2SpeechHandler = new TextToSpeechHandler(this, this);
        mText2Speech = new TextToSpeech(this, this);
    } else {
        // , ??
        mWebView = (WebView) mChatHead.findViewById(R.id.webview);
        mWebViewClient = new RealtimeBroadcastWebViewClient(this, mWebView, this);
        mWebViewClient.setBackgroundTransparent();

        String url = mBroadcastData.getMessage();
        if (url.indexOf("?") > 0) {
            if (!url.contains("UUID=")) {
                url += ("&UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                url += ("&APPID=" + getApplicationContext().getPackageName());
            }
        } else {
            if (!url.contains("UUID=")) {
                url += ("?UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                if (!url.contains("UUID=")) {
                    url += ("?APPID=" + getApplicationContext().getPackageName());
                } else {
                    url += ("&APPID=" + getApplicationContext().getPackageName());
                }
            }
        }
        mWebViewClient.loadUrl(url);
    }
    mChatHead.setTag(mBroadcastIndex);

    //        mChatHead.findViewById(R.id.btn_dismiss).setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                removeChatHead();
    //            }
    //        });

    /**
     * To create an overlay view, when setting up the LayoutParams DON'T set the type to TYPE_SYSTEM_OVERLAY.
            
     Instead set it to TYPE_PHONE.
            
     Use the following flags:
     FLAG_NOT_TOUCH_MODAL
     FLAG_WATCH_OUTSIDE_TOUCH
     FLAG_NOT_TOUCH_MODAL << I found this one to be quite important. Without it,
     focus is given to the overlay and soft-key (home, menu, etc.) presses are not passed to the activity below.
     */
    int flag = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, flag, 0,
            PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.CENTER;

    /**
     * do not use...
    mChatHead.findViewById(R.id.txt_title).setOnTouchListener(new View.OnTouchListener() {
    private int initialX;
    private int initialY;
    private float initialTouchX;
    private float initialTouchY;
            
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                initialX = params.x;
                initialY = params.y;
                initialTouchX = event.getRawX();
                initialTouchY = event.getRawY();
                return true;
            case MotionEvent.ACTION_UP:
                return true;
            case MotionEvent.ACTION_MOVE:
                params.x = initialX + (int) (event.getRawX() - initialTouchX);
                params.y = initialY + (int) (event.getRawY() - initialTouchY);
                windowManager.updateViewLayout(mChatHead, params);
                return true;
        }
        return false;
    }
    });
    */
    addChatHead(mChatHead, params);
}

From source file:com.jefftharris.passwdsafe.PreferencesFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_DEFAULT_FILE: {
        if (resultCode != Activity.RESULT_OK) {
            break;
        }/*from www  .  j a  v  a 2  s . c  o  m*/
        Intent val = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        setDefFilePref((val != null) ? val.getData().toString() : null);
        break;
    }
    default: {
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
    }
}

From source file:com.gsma.rcs.ri.sharing.geoloc.InitiateGeolocSharing.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;/*from w w w.j a  va 2  s  .  c om*/
    }
    switch (requestCode) {
    case SELECT_GEOLOCATION:
        /* Get selected geoloc */
        mGeoloc = data.getParcelableExtra(EditGeoloc.EXTRA_GEOLOC);
        mPositionView.setText(mGeoloc.toString());
        /* Enable invite button */
        mInviteBtn.setEnabled(true);
        break;
    }
}