Example usage for android.content Intent putExtras

List of usage examples for android.content Intent putExtras

Introduction

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

Prototype

public @NonNull Intent putExtras(@NonNull Bundle extras) 

Source Link

Document

Add a set of extended data to the intent.

Usage

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
  * /* w  w  w .j  a v  a2s.  co  m*/
  */
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // Handle item selection
    switch (item.getItemId()) {

    case R.id.deleteWaypointsMenuItem:

        // clear all waypoints with confirmation dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.are_you_sure).setCancelable(true)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        Waypoints.deleteAll(app.getDatabase());

                        updateWaypointsArray();// cursor.requery();

                        waypointsArrayAdapter.setItems(waypoints);
                        waypointsArrayAdapter.notifyDataSetChanged();

                        Toast.makeText(WaypointsListActivity.this, R.string.all_waypoints_deleted,
                                Toast.LENGTH_SHORT).show();

                    }

                }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();

        alert.show();

        return true;

    // import waypoints from external file
    case R.id.importMenuItem:

        // this.importFromTextFile();

        this.importFromXMLFile();

        return true;

    case R.id.exportMenuItem:

        exportWaypoints();

        return true;

    case R.id.showMapMenuItem:

        // startActivity(new Intent(this, WaypointsMapActivity.class));

        Intent i = new Intent(this, MyMapActivity.class);

        // using Bundle to pass track id into new activity
        Bundle b = new Bundle();
        b.putInt("mode", Constants.SHOW_ALL_WAYPOINTS);

        i.putExtras(b);
        startActivity(i);

        return true;

    default:

        return super.onOptionsItemSelected(item);

    }

}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
 * Show current waypoint on map//w w w .  ja v a2s. c om
 * 
 * @param waypointId
 *            Id of the requested waypoint
 */
protected void showOnMap(long waypointId) {

    com.balakrish.gpstracker.db.Waypoint wp = Waypoints.get(app.getDatabase(), waypointId);

    Intent i = new Intent(this, MyMapActivity.class);

    // using Bundle to pass track id into new activity
    Bundle b = new Bundle();

    b.putInt("mode", Constants.SHOW_WAYPOINT);
    b.putInt("latE6", wp.getLatE6());
    b.putInt("lngE6", wp.getLngE6());

    i.putExtras(b);
    startActivity(i);

}

From source file:com.example.carrie.carrie_test1.scandrug.java

public void geturl() {
    AsyncTask<Integer, Void, Void> task = new AsyncTask<Integer, Void, Void>() {
        @Override//w  ww.jav a2s .co  m
        protected Void doInBackground(Integer... integers) {
            String insertUrl = "http://54.65.194.253/Drug/qrcode.php?urlcode=" + urlcode;
            OkHttpClient client = new OkHttpClient();
            Log.d("uuuuuurl", insertUrl);
            okhttp3.Request request = new okhttp3.Request.Builder().url(insertUrl).build();
            Log.d("okhttpurl", "2222");
            try {
                okhttp3.Response response = client.newCall(request).execute();
                Log.d("okhttpurl", "1111");
                JSONArray array = new JSONArray(response.body().string());
                Log.d("okhttpurl", "33333");
                JSONObject object = array.getJSONObject(0);
                Log.d("okhttpurl", "16666");
                Log.d("okhttpurl", object.getString("id"));
                if ((object.getString("id")).equals("nodata")) {
                    Log.d("okht2tp", "4442222");
                    //normalDialogEvent();
                } else {

                    Log.d("nodata", "noooooooo");
                }

                Log.d("searchtest", array.toString());
                for (int i = 0; i < array.length(); i++) {

                    object = array.getJSONObject(i);

                    mydata = new MyData(object.getInt("id"), object.getString("chineseName"),
                            object.getString("image"), object.getString("indication"),
                            object.getString("englishName"), object.getString("licenseNumber"),
                            object.getString("category"), object.getString("component"),
                            object.getString("maker_Country"), object.getString("applicant"),
                            object.getString("maker_Name"), object.getString("QRCode"));

                }

            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            Intent it = new Intent(scandrug.this, FourthActivity.class);
            Log.d("customadapter2", "2");
            Bundle bundle = new Bundle();
            Log.d("customadapter2", "3");
            bundle.putInt("id", mydata.getId());
            Log.d("customadapter2", "4");
            bundle.putString("image", mydata.getImage_link());
            bundle.putString("chineseName", mydata.getChineseName());
            bundle.putString("indication", mydata.getIndication());
            bundle.putString("englishName", mydata.getEnglishName());
            bundle.putString("licenseNumber", mydata.getLicenseNumber());
            bundle.putString("category", mydata.getCategory());
            bundle.putString("component", mydata.getComponent());
            bundle.putString("maker_Country", mydata.getMaker_Country());
            bundle.putString("applicant", mydata.getApplicant());
            bundle.putString("maker_Name", mydata.getMaker_Name());

            Log.d("customadapter2", "5");
            it.putExtras(bundle);

            startActivity(it);
            Log.d("customadapter2", "6");

        }
    };
    task.execute();

}

From source file:com.adamas.client.android.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    } else if (id == R.id.action_scan_qr_code) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            IntentIntegrator integrator = new IntentIntegrator(this);
            integrator.initiateScan();//from  ww  w .ja va  2s  .c  om
        } else {
            checkCameraPermission();
        }
    } else if (id == R.id.action_delete_connector) {
        if (_connectorfragment != null) {
            _connectorfragment.deleteConnector(_selectedAdamasConnector);
        }
    } else if (id == R.id.action_add_connector_manually) {
        Intent intent = new Intent(this, AddConnectorActivity.class);
        startActivityForResult(intent, MANUALLY_ADD_CONNECTOR_REQUEST_CODE);
    } else if (id == R.id.action_edit_connector) {
        Intent intent = new Intent(this, EditConnectorActivity.class);
        Bundle mBundle = new Bundle();
        mBundle.putSerializable(EditConnectorActivity.ADAMAS_CONNECTOR, _selectedAdamasConnector);
        intent.putExtras(mBundle);
        startActivityForResult(intent, MANUALLY_EDIT_CONNECTOR_REQUEST_CODE);
    } else if (id == R.id.action_import_connector_from_text) {
        Intent intent = new Intent(this, ImportTextActivity.class);
        startActivityForResult(intent, IMPORT_FROM_TEXT_REQUEST_CODE);
    } else if (id == R.id.action_import_connector_from_image) {
        if (false) {
            FileChooser fileChooser = new FileChooser(this);
            fileChooser.setFileListener(new FileChooser.FileSelectedListener() {
                @Override
                public void fileSelected(final File file) {
                    String name = file.getAbsolutePath();
                    name = name;
                }
            });
            fileChooser.showDialog();
        } else {
            // this is much better
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
                    .getAbsolutePath());
            intent.setDataAndType(uri, "image/jpeg");
            startActivityForResult(Intent.createChooser(intent, getString(R.string.open)),
                    IMPORT_FROM_FILE_REQUEST_CODE);
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:android.support.v7.media.RemotePlaybackClient.java

private void performSessionAction(final Intent intent, final String sessionId, Bundle extras,
        final SessionActionCallback callback) {
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
    if (sessionId != null) {
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);
    }//  w  w  w. ja v a 2 s. c  om
    if (extras != null) {
        intent.putExtras(extras);
    }
    logRequest(intent);
    mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() {
        @Override
        public void onResult(Bundle data) {
            if (data != null) {
                String sessionIdResult = inferMissingResult(sessionId,
                        data.getString(MediaControlIntent.EXTRA_SESSION_ID));
                MediaSessionStatus sessionStatus = MediaSessionStatus
                        .fromBundle(data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
                adoptSession(sessionIdResult);
                if (sessionIdResult != null) {
                    if (DEBUG) {
                        Log.d(TAG,
                                "Received result from " + intent.getAction() + ": data=" + bundleToString(data)
                                        + ", sessionId=" + sessionIdResult + ", sessionStatus="
                                        + sessionStatus);
                    }
                    try {
                        callback.onResult(data, sessionIdResult, sessionStatus);
                    } finally {
                        if (intent.getAction().equals(MediaControlIntent.ACTION_END_SESSION)
                                && sessionIdResult.equals(mSessionId)) {
                            setSessionId(null);
                        }
                    }
                    return;
                }
            }
            handleInvalidResult(intent, callback, data);
        }

        @Override
        public void onError(String error, Bundle data) {
            handleError(intent, callback, error, data);
        }
    });
}

From source file:com.jacr.instagramtrendreader.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.activity_main);

    /* Customizing ActionBar */
    Resources r = getResources();
    ActionBar ab = super.getActionBar(false);
    ab.setIcon(r.getDrawable(R.drawable.ic_menu_home));
    ab.setTitle(Util.getTitleActivity(getString(R.string.title_my_gallery_app)));

    /* Views */// w  ww  .j  a va  2s.  c o  m
    layoutThumbnail = (TableLayout) findViewById(R.id.layoutThumbnail);
    layoutThumbnail.setPadding(1, 1, 1, 1);

    /* Setting Viewpager and Indicator */
    mPager = (ViewPager) findViewById(R.id.pagerMain);
    mAdapter = new ViewPagerAdapter<MainFragment>(getSupportFragmentManager());
    mPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {
            int key = feedReader.getListThumbnailKeys().get(arg0);
            feedReader.highlightThumbnail(key);

        }

    });

    /* Receiver */
    mReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Bundle extras = intent.getExtras();
            if (action.contentEquals(ACTION_IMAGE_CLICK)) {
                int key = extras.getInt(ACTION_IMAGE_CLICK);
                if (key != -1) {
                    Intent in = new Intent(Main.this, ImageDetails.class);
                    Bundle b = new Bundle();

                    /*
                     * Warning with Error FAILED BINDED TRANSACTION: it
                     * happens When the transfer of "extras" out of memory.
                     * in This case, when images are sent in intent.
                     */
                    b.putSerializable(ImageDetails.KEY_THUMBNAIL_DATA, feedReader.getListThumbnailData());
                    b.putSerializable(ImageDetails.KEY_THUMBNAIL_KEYS, feedReader.getListThumbnailKeys());
                    b.putInt(ImageDetails.KEY_THUMBNAIL_ACTUAL_KEY, key);
                    in.putExtras(b);
                    startActivity(in);
                }

            }
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_IMAGE_CLICK);
    registerReceiver(mReceiver, filter);

    /* Load data from Instagram */
    cargarFeedReader();
}

From source file:au.com.wallaceit.reddinator.MainActivity.java

public void openLink(int position, int openType) {
    // get the item
    JSONObject item = listAdapter.getItem(position);
    switch (openType) {
    case 1:// ww w  .  ja  v a  2  s .  c o  m
        // open in the reddinator view
        Intent clickIntent1 = new Intent(context, ViewRedditActivity.class);
        Bundle extras = new Bundle();
        try {
            extras.putString(WidgetProvider.ITEM_ID, item.getString("name"));
            extras.putInt("itemposition", position);
            extras.putString(WidgetProvider.ITEM_URL, item.getString("url"));
            extras.putString(WidgetProvider.ITEM_PERMALINK, item.getString("permalink"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        clickIntent1.putExtras(extras);
        context.startActivity(clickIntent1);
        break;
    case 2:
        // open link in browser
        String url = null;
        try {
            url = item.getString("url");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Intent clickIntent2 = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        context.startActivity(clickIntent2);
        break;
    case 3:
        // open reddit comments page in browser
        String permalink = null;
        try {
            permalink = item.getString("permalink");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Intent clickIntent3 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.reddit.com" + permalink));
        context.startActivity(clickIntent3);
        break;
    }
}

From source file:eu.dirtyharry.androidopsiadmin.Main.java

public void getOpsiClientsTask() {
    final ProgressDialog dialog = ProgressDialog.show(Main.this, getString(R.string.gen_title_pleasewait),
            getString(R.string.pd_getclients), true);
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();//  w w  w.j  a  v  a2 s. c  o  m
            if (GlobalVar.getInstance().getError().equals("null")) {
                if (doit.equals("true")) {

                    Intent i = new Intent(Main.this, ShowOpsiClientsListView.class);
                    Bundle b = new Bundle();
                    b.putStringArrayList("allclients", allclients);
                    b.putStringArrayList("clientdescriptions", clientdescription);
                    b.putStringArrayList("clientmacs", clientmac);
                    b.putStringArrayList("clientnotes", clientnotes);
                    b.putStringArrayList("clientips", clientip);
                    b.putStringArrayList("clientinventorys", clientinventory);
                    b.putStringArrayList("clientlastseens", clientlastseen);
                    i.putExtras(b);
                    startActivityForResult(i, GET_OPSI_CLIENT_REQUEST);

                } else if (doit.equals("serverdown")) {
                    Toast.makeText(Main.this, String.format(getString(R.string.to_servernotrechable), serverip),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                new Functions().msgBox(Main.this, getString(R.string.gen_title_error),
                        GlobalVar.getInstance().getError(), false);
                // GlobalVar.getInstance().setError("null");
            }

        }
    };

    checkUpdate = new Thread() {
        public void run() {
            Looper.prepare();
            if (Networking.isServerUp(serverip, serverport, serverusername, serverpasswd)) {
                getOpsiClients("rpc", serverip, serverport, "host_getHashes", serverusername, serverpasswd);
                doit = "true";
            } else {
                doit = "serverdown";
                //
            }

            handler.sendEmptyMessage(0);

        }
    };
    checkUpdate.start();
    // RTM ????
    // checkUpdate.interrupt();
}

From source file:github.popeen.dsub.activity.SubsonicActivity.java

protected void restart(boolean resumePosition) {
    Intent intent = new Intent(this, this.getClass());
    intent.putExtras(getIntent());
    if (resumePosition) {
        intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
    } else {// w  w w. j  a  v  a2s  .com
        String fragmentType = Util.openToTab(this);
        intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
        intent.putExtra(Constants.FRAGMENT_POSITION, getDrawerItemId(fragmentType));
    }
    finish();
    Util.startActivityWithoutTransition(this, intent);
}