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:jp.co.brilliantservice.android.writertduri.HomeActivity.java

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

    String action = intent.getAction();
    if (TextUtils.isEmpty(action))
        return;/*  w w  w.java  2  s. c o  m*/

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

    // NdefMessage?
    String uri = "http://www.brilliantservice.co.jp/";
    NdefMessage message = createUriMessage(uri);

    // ??????????
    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:edu.stanford.mobisocial.dungbeetle.SettingsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //TODO handle here. 
    if (resultCode == RESULT_OK) {
        Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

        SharedPreferences.Editor editor = settings.edit();
        if (uri == null) {
            editor.putString("ringtone", "none");
        } else {//from ww w  .  j a  v a 2 s . c o  m
            editor.putString("ringtone", uri.toString());
        }
        editor.commit();
        Log.w("settings", uri.toString());

    }
}

From source file:com.ratebeer.android.gui.components.PosterService.java

private void callbackMessenger(Intent intent, int result) {
    if (intent.hasExtra(EXTRA_MESSENGER)) {
        // Prepare a message
        Messenger callback = intent.getParcelableExtra(EXTRA_MESSENGER);
        Message msg = Message.obtain();//from ww  w  . ja  v a 2 s.co  m
        msg.arg1 = result;
        try {
            // Send it back to the messenger, i.e. the activity
            callback.send(msg);
        } catch (RemoteException e) {
            Log.e(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME,
                    "Cannot call back to activity to deliver message '" + msg.toString() + "'");
        }
    }
}

From source file:com.afwsamples.testdpc.provision.PostProvisioningTask.java

public boolean performPostProvisioningOperations(Intent intent) {
    if (isPostProvisioningDone()) {
        return false;
    }/*from   w w  w.j  ava 2 s  .  c  o m*/
    markPostProvisioningDone();

    // From M onwards, permissions are not auto-granted, so we need to manually grant
    // permissions for TestDPC.
    if (Util.isAtLeastM()) {
        autoGrantRequestedPermissionsToSelf();
    }

    // Retreive the admin extras bundle, which we can use to determine the original context for
    // TestDPCs launch.
    PersistableBundle extras = intent.getParcelableExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE);
    if (BuildCompat.isAtLeastO()) {
        maybeSetAffiliationIds(extras);
    }

    // Hide the setup launcher when this app is the admin
    mContext.getPackageManager().setComponentEnabledSetting(
            new ComponentName(mContext, SETUP_MANAGEMENT_LAUNCH_ACTIVITY),
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

    return true;
}

From source file:com.meetingninja.csse.notes.NotesFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) { // EditNoteActivity
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                int listPosition = data.getIntExtra("listPosition", -1);
                Note editedNote = (Note) data.getParcelableExtra(Keys.Note.PARCEL);

                int _id = Integer.valueOf(editedNote.getID());

                // if (listPosition != -1)
                // updateNote(listPosition, editedNote);
                // else
                // updateNote(_id, editedNote);

                populateList();//from  w  w w .  j  a  v  a2 s .  c  om
            }
        } else {
            if (resultCode == Activity.RESULT_CANCELED) {
                // nothing to do here
            }
        } // end EditNoteActivity
    } else if (requestCode == 3) { // CreateNoteActivity
        if (resultCode == Activity.RESULT_OK) {
            Toast.makeText(getActivity(), "New Note Created", Toast.LENGTH_SHORT).show();
            populateList();
        }
    } // end CreateNoteActivity
}

From source file:com.readystatesoftware.android.geras.mqtt.GerasMqttService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String host = intent.getStringExtra(EXTRA_HOST);
    String apiKey = intent.getStringExtra(EXTRA_API_KEY);
    ArrayList<GerasSensorConfig> monitors = intent.getParcelableArrayListExtra(EXTRA_SENSOR_MONITORS);
    for (GerasSensorConfig m : monitors) {
        mSensorMonitorMap.put(m.getSensorType(), m);
    }//from w w w  . java 2 s . c o  m
    mLocationMonitor = intent.getParcelableExtra(EXTRA_LOCATION_MONTITOR);
    mNotificationTarget = (Class) intent.getSerializableExtra(EXTRA_NOTIFICATION_TARGET_CLASS);
    sIsRunning = true;
    showNotification();
    connect(host, apiKey);
    return Service.START_STICKY;
}

From source file:com.hippo.nimingban.ui.TypeSendActivity.java

private Bundle createArgs() {
    Bundle bundle = new Bundle();
    Intent intent = getIntent();
    if (intent != null) {
        bundle.putString(TypeSendFragment.KEY_ACTION, intent.getAction());
        bundle.putString(TypeSendFragment.KEY_TYPE, intent.getType());
        bundle.putInt(TypeSendFragment.KEY_SITE, intent.getIntExtra(KEY_SITE, -1));
        bundle.putString(TypeSendFragment.KEY_ID, intent.getStringExtra(KEY_ID));
        bundle.putString(TypeSendFragment.KEY_TEXT, intent.getStringExtra(KEY_TEXT));
        bundle.putString(TypeSendFragment.KEY_EXTRA_TEXT, intent.getStringExtra(Intent.EXTRA_TEXT));
        bundle.putParcelable(TypeSendFragment.KEY_EXTRA_STREAM, intent.getParcelableExtra(Intent.EXTRA_STREAM));
    }//from   w w w.  j a  v a  2s. c  om
    return bundle;
}

From source file:com.nbplus.vbroadlauncher.BroadcastWebViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Constants.OPEN_BETA_PHONE && LauncherSettings.getInstance(this).isSmartPhone()) {
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }//from   w w  w.  ja  va2 s.  co m
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    setContentView(R.layout.activity_broadcast_webview);

    Log.d(TAG, "BroadcastWebViewActivity onCreate()");
    WebView webView = (WebView) findViewById(R.id.webview);
    mWebViewClient = new BroadcastWebViewClient(this, webView);

    IntentFilter filter = new IntentFilter();
    filter.addAction(Constants.ACTION_BROWSER_ACTIVITY_CLOSE);
    filter.addAction(Constants.ACTION_IOT_DEVICE_LIST);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter);

    Intent i = getIntent();
    String url = null;
    if (i != null && Constants.ACTION_SHOW_NOTIFICATION_CONTENTS.equals(getIntent().getAction())) {
        url = getIntent().getStringExtra(Constants.EXTRA_SHOW_NOTIFICATION_CONTENTS);
    } else {
        mShortcutData = i.getParcelableExtra(Constants.EXTRA_NAME_SHORTCUT_DATA);
        url = mShortcutData.getDomain() + mShortcutData.getPath();
    }

    //url="http://183.98.53.165:8010/web_test/audio_autoplay.html";
    if (StringUtils.isEmptyString(url) || !Patterns.WEB_URL.matcher(url).matches()) {
        Log.e(TAG, "Wrong url ....");
        new AlertDialog.Builder(this).setMessage(R.string.alert_wrong_page_url)
                //.setTitle(R.string.alert_network_title)
                .setCancelable(true)
                .setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        finishActivity();
                    }
                }).show();
        return;
    } else {
        mWebViewClient.loadWebUrl(url);
    }
    Log.d(TAG, "start URL = " + url);
    setContentViewByOrientation();
}

From source file:com.liferay.alerts.activity.CommentsActivity.java

private void _registerBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_ADD_COMMENT);
    filter.addAction(ACTION_UPDATE_COMMENTS_LIST);

    _receiver = new BroadcastReceiver() {

        @Override/*ww  w .j ava  2 s. c o m*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            ListView listView = (ListView) findViewById(R.id.comments);

            if (ACTION_UPDATE_COMMENTS_LIST.equals(action)) {
                ArrayList<Alert> alerts = intent.getParcelableArrayListExtra(EXTRA_ALERTS);

                ArrayAdapter<Alert> adapter = new CommentListAdapter(getApplicationContext(), alerts);

                listView.setAdapter(adapter);
            } else if (ACTION_ADD_COMMENT.equals(action)) {
                Alert alert = intent.getParcelableExtra(EXTRA_ALERT);

                ArrayAdapter<Alert> adapter = (ArrayAdapter<Alert>) listView.getAdapter();

                adapter.add(alert);
            }
        }

    };

    _getBroadcastManager().registerReceiver(_receiver, filter);
}

From source file:com.github.pockethub.android.ui.issue.EditIssueActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_issue_edit);

    titleText = (EditText) findViewById(R.id.et_issue_title);
    bodyText = (EditText) findViewById(R.id.et_issue_body);
    milestoneGraph = findViewById(R.id.ll_milestone_graph);
    milestoneText = (TextView) findViewById(R.id.tv_milestone);
    milestoneClosed = findViewById(R.id.v_closed);
    assigneeAvatar = (ImageView) findViewById(R.id.iv_assignee_avatar);
    assigneeText = (TextView) findViewById(R.id.tv_assignee_name);
    labelsText = (TextView) findViewById(R.id.tv_labels);
    addImageFab = (FloatingActionButton) findViewById(R.id.fab_add_image);

    Intent intent = getIntent();

    if (savedInstanceState != null) {
        issue = savedInstanceState.getParcelable(EXTRA_ISSUE);
    }/*from ww  w  . j  a  v a2  s. c o  m*/
    if (issue == null) {
        issue = intent.getParcelableExtra(EXTRA_ISSUE);
    }
    if (issue == null) {
        issue = Issue.builder().build();
    }

    repository = InfoUtils.createRepoFromData(intent.getStringExtra(EXTRA_REPOSITORY_OWNER),
            intent.getStringExtra(EXTRA_REPOSITORY_NAME));

    checkCollaboratorStatus();

    setSupportActionBar((android.support.v7.widget.Toolbar) findViewById(R.id.toolbar));

    ActionBar actionBar = getSupportActionBar();
    if (issue.number() != null && issue.number() > 0) {
        if (IssueUtils.isPullRequest(issue)) {
            actionBar.setTitle(getString(R.string.pull_request_title) + issue.number());
        } else {
            actionBar.setTitle(getString(R.string.issue_title) + issue.number());
        }
    } else {
        actionBar.setTitle(R.string.new_issue);
    }
    actionBar.setSubtitle(InfoUtils.createRepoId(repository));
    avatars.bind(actionBar, (User) intent.getParcelableExtra(EXTRA_USER));

    titleText.addTextChangedListener(new TextWatcherAdapter() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            super.onTextChanged(s, start, before, count);
            updateSaveMenu(s);
        }
    });

    // @TargetApi() required to ensure build passes
    // noinspection Convert2Lambda
    addImageFab.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                Activity activity = EditIssueActivity.this;
                String permission = Manifest.permission.READ_EXTERNAL_STORAGE;

                if (ContextCompat.checkSelfPermission(activity,
                        permission) != PackageManager.PERMISSION_GRANTED) {
                    PermissionsUtils.askForPermission(activity, READ_PERMISSION_REQUEST, permission,
                            R.string.read_permission_title, R.string.read_permission_content);
                } else {
                    startImagePicker();
                }
            } else {
                startImagePicker();
            }
        }
    });

    updateSaveMenu();
    titleText.setText(issue.title());
    bodyText.setText(issue.body());
}