Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

In this page you can find the example usage for android.os Bundle get.

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:me.kglawrence.kerilawrence.book_park.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///ww w .j  a v a  2 s  .co  m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.barcode_capture);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);
    mDatabase = FirebaseDatabase.getInstance().getReference();

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus);
    } else {
        requestCameraPermission();
    }

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        studentId = (String) bundle.get("studentId");
        checkIn = (boolean) bundle.get("checkin");
        Log.d("tag", "" + studentId);
        Log.d("tag", "" + checkIn);
    }

    Snackbar.make(mGraphicOverlay, "Hold book up to camera", Snackbar.LENGTH_LONG).show();
}

From source file:com.mobilyzer.AccountSelector.java

private void getAuthToken(AccountManagerFuture<Bundle> result) {
    Logger.i("getAuthToken() called, result " + result);
    String errMsg = "Failed to get login cookie. ";
    Bundle bundle;//w ww .  ja  va 2s  .c o m
    try {
        bundle = result.getResult();
        Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
        if (intent != null) {
            // User input required. (A UI will pop up for user's consent to allow
            // this app access account information.)
            Logger.i("Starting account manager activity");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivity(intent);
        } else {
            Logger.i("Executing getCookie task");
            synchronized (this) {
                this.authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
                this.checkinFuture = checkinExecutor.submit(new GetCookieTask());
            }
        }
    } catch (OperationCanceledException e) {
        Logger.e(errMsg, e);
        throw new RuntimeException("Can't get login cookie", e);
    } catch (AuthenticatorException e) {
        Logger.e(errMsg, e);
        throw new RuntimeException("Can't get login cookie", e);
    } catch (IOException e) {
        Logger.e(errMsg, e);
        throw new RuntimeException("Can't get login cookie", e);
    }
}

From source file:com.brodev.socialapp.view.MusicPlaySong.java

/** Called when the activity is first created. */
@Override//from w w w.j  av  a  2 s. c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.music_player);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    user = (User) getApplication().getApplicationContext();
    colorView = new ColorView(getApplicationContext());

    Bundle bundle = getIntent().getExtras();

    music = (Music) bundle.get("song");

    if (music.getTitle().equals("")) {
        this.getMusicAdapter();
    }
    initView();
    // get comment fragment
    Bundle comment = new Bundle();
    comment.putString("type", "music_song");
    comment.putInt("itemId", Integer.parseInt(music.getSong_id()));
    comment.putInt("totalComment", Integer.parseInt(music.getTotal_comment()));
    comment.putInt("total_like", Integer.parseInt(music.getTotal_like()));
    comment.putBoolean("no_share", music.isShare());
    comment.putBoolean("is_liked", music.isLiked());
    comment.putBoolean("can_post_comment", music.isCanPostComment());

    CommentFragment commentFragment = new CommentFragment();
    commentFragment.setArguments(comment);
    getSupportFragmentManager().beginTransaction().add(R.id.commentfragment_wrap, commentFragment).commit();

}

From source file:edu.csh.coursebrowser.CourseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course);
    // Show the Up button in the action bar.
    this.getActionBar().setHomeButtonEnabled(false);
    map_item = new HashMap<String, Course>();
    map = new ArrayList<String>();
    Bundle args = this.getIntent().getExtras();
    this.setTitle(args.getCharSequence("title"));
    try {// w ww.ja  va 2 s. co m
        JSONObject jso = new JSONObject(args.get("args").toString());
        JSONArray jsa = new JSONArray(jso.getString("courses"));
        ListView lv = (ListView) this.findViewById(R.id.course_list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map);
        for (int i = 0; i < jsa.length(); ++i) {
            String s = jsa.getString(i);
            JSONObject obj = new JSONObject(s);
            Course course = new Course(obj.getString("title"), obj.getString("department"),
                    obj.getString("course"), obj.getString("description"), obj.getString("id"));
            addItem(course);
            Log.v("Added", course.toString());
        }
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String s = ((TextView) arg1).getText().toString();
                final Course course = map_item.get(s);
                new AsyncTask<String, String, String>() {
                    ProgressDialog p;

                    protected void onPreExecute() {
                        p = new ProgressDialog(CourseActivity.this);
                        p.setTitle("Fetching Info");
                        p.setMessage("Contacting Server...");
                        p.setCancelable(false);
                        p.show();
                    }

                    protected String doInBackground(String... dep) {
                        String params = "action=getSections&course=" + course.id;
                        Log.v("Params", params);
                        URL url;
                        String back = "";
                        try {
                            url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php");

                            URLConnection conn = url.openConnection();
                            conn.setDoOutput(true);
                            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
                            writer.write(params);
                            writer.flush();
                            String line;
                            BufferedReader reader = new BufferedReader(
                                    new InputStreamReader(conn.getInputStream()));

                            while ((line = reader.readLine()) != null) {
                                Log.v("Back:", line);
                                back += line;
                            }
                            writer.close();
                            reader.close();
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            return null;
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            p.dismiss();
                            return null;
                        }
                        return back;
                    }

                    protected void onPostExecute(String s) {
                        if (s == null || s == "") {
                            new AlertError(CourseActivity.this, "IO Error!").show();
                            return;
                        }
                        try {
                            JSONObject jso = new JSONObject(s);
                            JSONArray jsa = new JSONArray(jso.getString("sections"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            new AlertError(CourseActivity.this, "Invalid JSON From Server").show();
                            p.dismiss();
                            return;
                        }
                        Intent intent = new Intent(CourseActivity.this, SectionsActivity.class);
                        intent.putExtra("title", course.title);
                        intent.putExtra("id", course.id);
                        intent.putExtra("description", course.description);
                        intent.putExtra("args", s);
                        startActivity(intent);
                        p.dismiss();
                    }
                }.execute(course.id);
            }

        });

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        new AlertError(this, "Invalid JSON");
        e.printStackTrace();
    }

}

From source file:net.evendanan.pushingpixels.FragmentChauffeurActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    mIsActivityShown = true;// ww  w.j  a v  a 2 s  .co  m
    if (savedInstanceState == null) {
        //setting up the root of the UI.
        setRootFragment(createRootFragmentInstance());
        //now, checking if there is a request to add a fragment on-top of this one.
        Bundle activityArgs = getIntent().getExtras();
        if (activityArgs != null && activityArgs.containsKey(KEY_FRAGMENT_CLASS_TO_ADD)) {
            Class<? extends Fragment> fragmentClass = (Class<? extends Fragment>) activityArgs
                    .get(KEY_FRAGMENT_CLASS_TO_ADD);
            //not sure that this is a best-practice, but I still need to remove this from the activity's args
            activityArgs.remove(KEY_FRAGMENT_CLASS_TO_ADD);
            try {
                Fragment fragment = fragmentClass.newInstance();
                if (activityArgs.containsKey(KEY_FRAGMENT_ARGS_TO_ADD)) {
                    fragment.setArguments(activityArgs.getBundle(KEY_FRAGMENT_ARGS_TO_ADD));
                    activityArgs.remove(KEY_FRAGMENT_CLASS_TO_ADD);
                }
                addFragmentToUi(fragment, FragmentUiContext.RootFragment);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:edu.csh.coursebrowser.DepartmentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_departments);
    // Show the Up button in the action bar.
    // getActionBar().setDisplayHomeAsUpEnabled(false);
    this.getActionBar().setHomeButtonEnabled(true);
    final Bundle b = this.getIntent().getExtras();
    map_item = new HashMap<String, Department>();
    map = new ArrayList<String>();
    Bundle args = this.getIntent().getExtras();
    this.setTitle(args.getCharSequence("from"));
    try {/*from  w  ww.  j a v  a  2 s .c om*/
        JSONObject jso = new JSONObject(args.get("args").toString());
        JSONArray jsa = new JSONArray(jso.getString("departments"));
        ListView lv = (ListView) this.findViewById(R.id.department_list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map);
        for (int i = 0; i < jsa.length(); ++i) {
            String s = jsa.getString(i);
            JSONObject obj = new JSONObject(s);
            Department dept = new Department(obj.getString("title"), obj.getString("id"),
                    obj.getString("code"));
            addItem(dept);
            Log.v("Added", dept.toString());
        }
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String s = ((TextView) arg1).getText().toString();
                final Department department = map_item.get(s);
                new AsyncTask<String, String, String>() {
                    ProgressDialog p;

                    protected void onPreExecute() {
                        p = new ProgressDialog(DepartmentActivity.this);
                        p.setTitle("Fetching Info");
                        p.setMessage("Contacting Server...");
                        p.setCancelable(false);
                        p.show();
                    }

                    protected String doInBackground(String... dep) {
                        String params = "action=getCourses&department=" + dep[0] + "&quarter="
                                + b.getString("qCode");
                        Log.v("Params", params);
                        URL url;
                        String back = "";
                        try {
                            url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php");

                            URLConnection conn = url.openConnection();
                            conn.setDoOutput(true);
                            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
                            writer.write(params);
                            writer.flush();
                            String line;
                            BufferedReader reader = new BufferedReader(
                                    new InputStreamReader(conn.getInputStream()));

                            while ((line = reader.readLine()) != null) {
                                Log.v("Back:", line);
                                back += line;
                            }
                            writer.close();
                            reader.close();
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            return null;
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            p.dismiss();
                            return null;
                        }
                        return back;
                    }

                    protected void onPostExecute(String s) {
                        if (s == null || s == "") {
                            new AlertError(DepartmentActivity.this, "IO Error!").show();
                            return;
                        }

                        try {
                            JSONObject jso = new JSONObject(s);
                            JSONArray jsa = new JSONArray(jso.getString("courses"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            new AlertError(DepartmentActivity.this, "Invalid JSON From Server").show();
                            p.dismiss();
                            return;
                        }
                        Intent intent = new Intent(DepartmentActivity.this, CourseActivity.class);
                        intent.putExtra("title", department.title);
                        intent.putExtra("id", department.id);
                        intent.putExtra("code", department.code);
                        intent.putExtra("args", s);
                        startActivity(intent);
                        p.dismiss();
                    }
                }.execute(department.id);
            }

        });

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        new AlertError(this, "Invalid JSON");
        e.printStackTrace();
    }

}

From source file:com.ijuru.kumva.app.activity.SearchActivity.java

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

    this.definitionAdapter = new EntryListAdapter(this);
    this.suggestionAdapter = new SuggestionListAdapter(this);

    ListView listResults = (ListView) findViewById(R.id.listresults);
    listResults.setOnItemClickListener(this);

    // Check for an initial query passed via the intent
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String initQuery = (String) extras.get("query");
        if (initQuery != null)
            doSearch(initQuery);// www. j a  v a  2  s .c o  m
    }
}

From source file:edu.mit.media.funf.funftowotk.MainPipeline.java

public Boolean checkValidData(Bundle data) {

    String probe = data.getString("PROBE").replace(SettingsActivity.probe_prefix, "");

    if (probe.equals("CallLogProbe")) {

        ArrayList calls = (ArrayList) data.get("CALLS");

        if (calls.isEmpty()) {
            //Log.i("DataLog",calls.toString());
            return false;
        }/*from   w  ww . j  a va  2s . co m*/
    } else if (probe.equals("SMSProbe")) {

        ArrayList messages = (ArrayList) data.get("MESSAGES");

        if (messages.isEmpty()) {
            //Log.i("DataLog",messages.toString());
            return false;
        }
    }

    return true;
}

From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java

@Override
public String promote(final Activity activity, String inAuthority, final String token) {
    final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority;
    final AccountManager am = AccountManager.get(activity);
    //      Bundle options = new Bundle();
    //      if (token != null) {
    //         options.putString(Constants.PROMOTION_TOKEN, token);
    //      }//from  w  w  w  .  j  a v  a 2s. c o  m
    final Account a = new Account(Constants.getAccountName(activity), Constants.getAccountType(activity));
    final String userDataString = am.getUserData(a, AccountManager.KEY_USERDATA);

    invalidateToken(activity, authority);

    am.getAuthToken(new Account(Constants.getAccountName(activity), Constants.getAccountType(activity)),
            authority, null, null, new AccountManagerCallback<Bundle>() {
                @Override
                public void run(AccountManagerFuture<Bundle> result) {
                    Bundle bundle = null;
                    try {
                        bundle = result.getResult();
                        Intent launch = (Intent) bundle.get(AccountManager.KEY_INTENT);
                        if (launch != null) {
                            launch.putExtra(Constants.KEY_AUTHORITY, authority);
                            launch.putExtra(Constants.PROMOTION_TOKEN, token);
                            launch.putExtra(Constants.OLD_DATA, userDataString);
                            activity.startActivityForResult(launch, SC_AUTH_ACTIVITY_REQUEST_CODE);
                        } else if (bundle.getString(AccountManager.KEY_AUTHTOKEN) != null) {
                            //                         am.setAuthToken(a, authority, bundle.getString(AccountManager.KEY_AUTHTOKEN));
                            //                         am.addAccountExplicitly(a, null, null);
                            // no token acquired
                        } else {
                            storeAnonymousToken(token, authority, am, a);
                        }
                    } catch (Exception e) {
                        // revert the invalidated token
                        storeAnonymousToken(token, authority, am, a);
                        return;
                    }
                }
            }, null);
    return null;
}

From source file:com.google.android.apps.authenticator.dataimport.Importer.java

private boolean tryImportPreferencesFromBundle(Bundle bundle, SharedPreferences preferences) {
    SharedPreferences.Editor preferencesEditor = preferences.edit();
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        if (value instanceof Boolean) {
            preferencesEditor.putBoolean(key, (Boolean) value);
        } else if (value instanceof Float) {
            preferencesEditor.putFloat(key, (Float) value);
        } else if (value instanceof Integer) {
            preferencesEditor.putInt(key, (Integer) value);
        } else if (value instanceof Long) {
            preferencesEditor.putLong(key, (Long) value);
        } else if (value instanceof String) {
            preferencesEditor.putString(key, (String) value);
        } else {/*from   ww w .ja  v  a  2 s .  c  o  m*/
            // Ignore: can only be Set<String> at the moment (API Level 11+), which we don't use anyway.
        }
    }
    return preferencesEditor.commit();
}