List of usage examples for android.content Intent getBundleExtra
public Bundle getBundleExtra(String name)
From source file:com.tumanako.dash.DashMessages.java
@Override public void onReceive(Context context, Intent intent) { // Get the 'Action' from the intent: String action = intent.getAction(); // Get other data (if it was sent): Integer intData = null;//from w w w.j ava 2 s . c o m Float floatData = null; String stringData = null; Bundle bundleData = null; if (intent.hasExtra(DASHMESSAGE_INT)) intData = intent.getIntExtra(DASHMESSAGE_INT, 0); if (intent.hasExtra(DASHMESSAGE_FLOAT)) floatData = intent.getFloatExtra(DASHMESSAGE_FLOAT, 0f); if (intent.hasExtra(DASHMESSAGE_STRING)) stringData = intent.getStringExtra(DASHMESSAGE_STRING); if (intent.hasExtra(DASHMESSAGE_DATA)) bundleData = intent.getBundleExtra(DASHMESSAGE_DATA); // --DEBUG!-- Log.i(com.tumanako.ui.UIActivity.APP_TAG, String.format( " DashMessages -> Msg Rec: %d", message) ); parent.messageReceived(action, intData, floatData, stringData, bundleData); }
From source file:com.deliciousdroid.activity.BrowseBookmarks.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browse_bookmarks); Intent intent = getIntent(); Uri data = intent.getData();/*from w ww. ja va 2 s .c o m*/ FragmentManager fm = getSupportFragmentManager(); FragmentTransaction t = fm.beginTransaction(); Fragment bookmarkFrag; if (fm.findFragmentById(R.id.listcontent) == null) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { Bundle searchData = intent.getBundleExtra(SearchManager.APP_DATA); if (searchData != null) { tagname = searchData.getString("tagname"); username = searchData.getString("username"); unread = searchData.getBoolean("unread"); } query = intent.getStringExtra(SearchManager.QUERY); if (intent.hasExtra("username")) { username = intent.getStringExtra("username"); } if (data != null && data.getUserInfo() != null) { username = data.getUserInfo(); } } else { if (data != null) { if (data.getUserInfo() != "") { username = data.getUserInfo(); } else username = mAccount.name; tagname = data.getQueryParameter("tagname"); unread = data.getQueryParameter("unread") != null; path = data.getPath(); } } if (isMyself()) { bookmarkFrag = new BrowseBookmarksFragment(); } else { bookmarkFrag = new BrowseBookmarkFeedFragment(); } t.add(R.id.listcontent, bookmarkFrag); } else { if (savedInstanceState != null) { username = savedInstanceState.getString(STATE_USERNAME); tagname = savedInstanceState.getString(STATE_TAGNAME); unread = savedInstanceState.getBoolean(STATE_UNREAD); query = savedInstanceState.getString(STATE_QUERY); path = savedInstanceState.getString(STATE_PATH); } bookmarkFrag = fm.findFragmentById(R.id.listcontent); } if (isMyself()) { if (query != null && !query.equals("")) { ((BrowseBookmarksFragment) bookmarkFrag).setSearchQuery(query, username, tagname, unread); } else { ((BrowseBookmarksFragment) bookmarkFrag).setQuery(username, tagname, unread); } } else { if (query != null && !query.equals("")) { ((BrowseBookmarkFeedFragment) bookmarkFrag).setQuery(username, tagname); } else { ((BrowseBookmarkFeedFragment) bookmarkFrag).setQuery(username, query); } } BrowseTagsFragment tagFrag = (BrowseTagsFragment) fm.findFragmentById(R.id.tagcontent); if (tagFrag != null) { tagFrag.setAccount(username); } if (path != null && path.contains("tags")) { t.hide(fm.findFragmentById(R.id.maincontent)); findViewById(R.id.panel_collapse_button).setVisibility(View.GONE); } else { if (tagFrag != null) { t.hide(tagFrag); } } Fragment addFrag = fm.findFragmentById(R.id.addcontent); if (addFrag != null) { t.hide(addFrag); } t.commit(); }
From source file:com.pindroid.activity.BrowseBookmarks.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browse_bookmarks); Intent intent = getIntent(); Uri data = intent.getData();/*from w w w . j a va2 s. co m*/ FragmentManager fm = getSupportFragmentManager(); FragmentTransaction t = fm.beginTransaction(); if (fm.findFragmentById(R.id.listcontent) == null) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { Bundle searchData = intent.getBundleExtra(SearchManager.APP_DATA); if (searchData != null) { tagname = searchData.getString("tagname"); app.setUsername(searchData.getString("username")); unread = searchData.getBoolean("unread"); } query = intent.getStringExtra(SearchManager.QUERY); if (intent.hasExtra("username")) { app.setUsername(intent.getStringExtra("username")); } if (data != null) { feed = data.getQueryParameter("feed"); if (data.getUserInfo() != null) { app.setUsername(data.getUserInfo()); } } } else { if (data != null) { tagname = data.getQueryParameter("tagname"); feed = data.getQueryParameter("feed"); unread = data.getQueryParameter("unread") != null; path = data.getPath(); } } if (feed == null || feed.equals("")) { bookmarkFrag = new BrowseBookmarksFragment(); } else { bookmarkFrag = new BrowseBookmarkFeedFragment(); } t.add(R.id.listcontent, bookmarkFrag); } else { if (savedInstanceState != null) { tagname = savedInstanceState.getString(STATE_TAGNAME); unread = savedInstanceState.getBoolean(STATE_UNREAD); query = savedInstanceState.getString(STATE_QUERY); path = savedInstanceState.getString(STATE_PATH); feed = savedInstanceState.getString(STATE_FEED); } bookmarkFrag = fm.findFragmentById(R.id.listcontent); } if (feed == null || feed.equals("")) { if (query != null && !query.equals("")) { ((BrowseBookmarksFragment) bookmarkFrag).setSearchQuery(query, app.getUsername(), tagname, unread); } else { ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), tagname, unread ? "unread" : null); } ((BrowseBookmarksFragment) bookmarkFrag).refresh(); } else { if (query == null || query.equals("")) { ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), tagname, feed); } else { ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), query, feed); } } BrowseTagsFragment tagFrag = (BrowseTagsFragment) fm.findFragmentById(R.id.tagcontent); if (tagFrag != null) { tagFrag.setAccount(app.getUsername()); } if (path != null && path.contains("tags")) { t.hide(fm.findFragmentById(R.id.maincontent)); findViewById(R.id.panel_collapse_button).setVisibility(View.GONE); } else { if (tagFrag != null) { t.hide(tagFrag); } } Fragment addFrag = fm.findFragmentById(R.id.addcontent); if (addFrag != null) { t.hide(addFrag); } t.commit(); }
From source file:com.mobilesolutionworks.android.httpcache.WorksHttpCacheService.java
protected void refreshData(Intent intent) { // rebuild into hierarchical uri String local = intent.getStringExtra("local"); String remote = intent.getStringExtra("remote"); if (mQueues.contains(local)) { return;// w w w .j ava 2 s . c o m } mQueues.add(local); String _method = intent.getStringExtra("method"); WorksHttpRequest.Method method = WorksHttpRequest.Method.GET; if ("POST".equals(_method)) { method = WorksHttpRequest.Method.POST; } WorksHttpRequest config = new WorksHttpRequest(); config.method = method; config.url = remote; Bundle params = intent.getBundleExtra("params"); if (params != null) { for (String key : params.keySet()) { String value = params.getString(key); if (!TextUtils.isEmpty(value)) { config.setPostParam(key, value); } } } int cache = intent.getIntExtra("cache", 0); if (cache == 0) { cache = 60; } cache *= 1000; int timeout = intent.getIntExtra("timeout", 0); if (timeout == 0) { timeout = 10; } timeout *= 1000; WorksHttpFutureTask<String> task = getSaveTask(local, cache, timeout); task.execute(config, mHandler, mExecutors); }
From source file:bolts.AppLinkTest.java
public void testGeneralMeasurementEventsBroadcast() throws Exception { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); i.putExtra("foo", "bar"); ArrayList<String> arr = new ArrayList<>(); arr.add("foo2"); arr.add("bar2"); i.putExtra("foobar", arr); Map<String, String> other = new HashMap<>(); other.put("yetAnotherFoo", "yetAnotherBar"); final CountDownLatch lock = new CountDownLatch(1); final String[] receivedStrings = new String[5]; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext()); manager.registerReceiver(new BroadcastReceiver() { @Override// w w w. j a va 2s. com public void onReceive(Context context, Intent intent) { String eventName = intent.getStringExtra("event_name"); Bundle eventArgs = intent.getBundleExtra("event_args"); receivedStrings[0] = eventName; receivedStrings[1] = eventArgs.getString("foo"); receivedStrings[2] = eventArgs.getString("foobar"); receivedStrings[3] = eventArgs.getString("yetAnotherFoo"); receivedStrings[4] = eventArgs.getString("intentData"); lock.countDown(); } }, new IntentFilter("com.parse.bolts.measurement_event")); MeasurementEvent.sendBroadcastEvent(getInstrumentation().getTargetContext(), "myEventName", i, other); lock.await(2000, TimeUnit.MILLISECONDS); assertEquals("myEventName", receivedStrings[0]); assertEquals("bar", receivedStrings[1]); assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]); assertEquals("yetAnotherBar", receivedStrings[3]); assertEquals("http://www.example.com", receivedStrings[4]); }
From source file:ie.programmer.catcher.AppLinkTest.java
public void testGeneralMeasurementEventsBroadcast() throws Exception { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); i.putExtra("foo", "bar"); ArrayList<String> arr = new ArrayList<>(); arr.add("foo2"); arr.add("bar2"); i.putExtra("foobar", arr); Map<String, String> other = new HashMap<>(); other.put("yetAnotherFoo", "yetAnotherBar"); final CountDownLatch lock = new CountDownLatch(1); final String[] receivedStrings = new String[5]; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext()); manager.registerReceiver(new BroadcastReceiver() { @Override/* w ww . ja va 2 s . c o m*/ public void onReceive(Context context, Intent intent) { String eventName = intent.getStringExtra("event_name"); Bundle eventArgs = intent.getBundleExtra("event_args"); receivedStrings[0] = eventName; receivedStrings[1] = eventArgs.getString("foo"); receivedStrings[2] = eventArgs.getString("foobar"); receivedStrings[3] = eventArgs.getString("yetAnotherFoo"); receivedStrings[4] = eventArgs.getString("intentData"); lock.countDown(); } }, new IntentFilter("com.parse.bolts.measurement_event")); // MeasurementEvent.sendBroadcastEvent(getInstrumentation().getTargetContext(), "myEventName", i, other); lock.await(2000, TimeUnit.MILLISECONDS); assertEquals("myEventName", receivedStrings[0]); assertEquals("bar", receivedStrings[1]); assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]); assertEquals("yetAnotherBar", receivedStrings[3]); assertEquals("http://www.example.com", receivedStrings[4]); }
From source file:bolts.AppLinkTest.java
public void testAppLinkNavInEventBroadcast() throws Exception { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); Bundle appLinkData = new Bundle(); appLinkData.putString("target_url", "http://www.example2.com"); Bundle appLinkRefererData = new Bundle(); appLinkRefererData.putString("url", "referer://"); appLinkRefererData.putString("app_name", "Referrer App"); appLinkRefererData.putString("package", "com.bolts.referrer"); appLinkData.putBundle("referer_app_link", appLinkRefererData); Bundle applinkExtras = new Bundle(); applinkExtras.putString("token", "a_token"); appLinkData.putBundle("extras", applinkExtras); i.putExtra("al_applink_data", appLinkData); final CountDownLatch lock = new CountDownLatch(1); final String[] receivedStrings = new String[7]; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext()); manager.registerReceiver(new BroadcastReceiver() { @Override//from www . j a v a 2s. co m public void onReceive(Context context, Intent intent) { String eventName = intent.getStringExtra("event_name"); Bundle eventArgs = intent.getBundleExtra("event_args"); receivedStrings[0] = eventName; receivedStrings[1] = eventArgs.getString("targetURL"); receivedStrings[2] = eventArgs.getString("inputURL"); receivedStrings[3] = eventArgs.getString("refererURL"); receivedStrings[4] = eventArgs.getString("refererAppName"); receivedStrings[5] = eventArgs.getString("extras/token"); receivedStrings[6] = eventArgs.getString("sourceApplication"); lock.countDown(); } }, new IntentFilter("com.parse.bolts.measurement_event")); Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(getInstrumentation().getTargetContext(), i); lock.await(2000, TimeUnit.MILLISECONDS); assertEquals("al_nav_in", receivedStrings[0]); assertEquals("http://www.example2.com", receivedStrings[1]); assertEquals("http://www.example.com", receivedStrings[2]); assertEquals("referer://", receivedStrings[3]); assertEquals("Referrer App", receivedStrings[4]); assertEquals("a_token", receivedStrings[5]); assertEquals("com.bolts.referrer", receivedStrings[6]); }
From source file:com.google.android.apps.muzei.SourceSubscriberService.java
@Override protected void onHandleIntent(Intent intent) { if (intent == null || intent.getAction() == null) { return;/* w ww.ja va 2s. c o m*/ } String action = intent.getAction(); if (!ACTION_PUBLISH_STATE.equals(action)) { return; } // Handle API call from source String token = intent.getStringExtra(EXTRA_TOKEN); ComponentName selectedSource = SourceManager.getSelectedSource(this); if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) { Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for " + selectedSource); return; } SourceState state = null; if (intent.hasExtra(EXTRA_STATE)) { Bundle bundle = intent.getBundleExtra(EXTRA_STATE); if (bundle != null) { state = SourceState.fromBundle(bundle); } } if (state == null) { // If there is no state, there is nothing to change return; } ContentValues values = new ContentValues(); values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString()); values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true); values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription()); values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable()); JSONArray commandsSerialized = new JSONArray(); int numSourceActions = state.getNumUserCommands(); boolean supportsNextArtwork = false; for (int i = 0; i < numSourceActions; i++) { UserCommand command = state.getUserCommandAt(i); if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) { supportsNextArtwork = true; } else { commandsSerialized.put(command.serialize()); } } values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork); values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString()); ContentResolver contentResolver = getContentResolver(); Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { selectedSource.flattenToShortString() }, null, null); if (existingSource != null && existingSource.moveToFirst()) { Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, existingSource.getLong(0)); contentResolver.update(sourceUri, values, null, null); } else { contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values); } if (existingSource != null) { existingSource.close(); } Artwork artwork = state.getCurrentArtwork(); if (artwork != null) { artwork.setComponentName(selectedSource); contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues()); // Download the artwork contained from the newly published SourceState startService(TaskQueueService.getDownloadCurrentArtworkIntent(this)); } }
From source file:com.hippo.scene.StageActivity.java
/** * @return {@code true} for start scene/*from w ww . j av a 2 s. c o m*/ */ private boolean startSceneFromIntent(Intent intent) { String clazzStr = intent.getStringExtra(KEY_SCENE_NAME); if (null == clazzStr) { return false; } Class clazz; try { clazz = Class.forName(clazzStr); } catch (ClassNotFoundException e) { Log.e(TAG, "Can't find class " + clazzStr, e); return false; } Bundle args = intent.getBundleExtra(KEY_SCENE_ARGS); Announcer announcer = onStartSceneFromIntent(clazz, args); if (announcer == null) { return false; } startScene(announcer); return true; }
From source file:com.google.samples.apps.gcmplayground.MyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); registerButton = (Button) findViewById(R.id.register_button); unregisterButton = (Button) findViewById(R.id.unregister_button); stringIdentifierField = (EditText) findViewById(R.id.string_identifier); registrationTokenFieldView = (TextView) findViewById(R.id.registeration_token); statusView = (TextView) findViewById(R.id.status); downstreamBundleView = (TextView) findViewById(R.id.downstream_bundle); upstreamMessageField = (EditText) findViewById(R.id.upstream_message); sendButton = (Button) findViewById(R.id.button_send); subscribeTopicButton = (Button) findViewById(R.id.topic_subscribe); topicField = (EditText) findViewById(R.id.topic_name); progressBar = (ProgressBar) findViewById(R.id.progress_bar); gcm = GoogleCloudMessaging.getInstance(this); pubSub = GcmPubSub.getInstance(this); // If Play Services is not up to date, quit the app. checkPlayServices();/*from w w w . ja v a2 s.c o m*/ registerButton.setOnClickListener(this); unregisterButton.setOnClickListener(this); subscribeTopicButton.setOnClickListener(this); sendButton.setOnClickListener(this); // Restore from saved instance state if (savedInstanceState != null) { token = savedInstanceState.getString(RegistrationConstants.EXTRA_KEY_TOKEN, ""); if (token != "") { updateUI("Registration SUCCEEDED", true); } } mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { boolean sentToken = intent.getBooleanExtra(RegistrationConstants.SENT_TOKEN_TO_SERVER, false); token = intent.getStringExtra(RegistrationConstants.EXTRA_KEY_TOKEN); if (!sentToken) { updateUI("Registration FAILED", false); } } }; mDownstreamBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String from = intent.getStringExtra(RegistrationConstants.SENDER_ID); Bundle data = intent.getBundleExtra(RegistrationConstants.EXTRA_KEY_BUNDLE); String message = data.getString(RegistrationConstants.EXTRA_KEY_MESSAGE); Log.d(TAG, "Received from >" + from + "< with >" + data.toString() + "<"); Log.d(TAG, "Message: " + message); String action = data.getString(RegistrationConstants.ACTION); String status = data.getString(RegistrationConstants.STATUS); if (RegistrationConstants.REGISTER_NEW_CLIENT.equals(action) && RegistrationConstants.STATUS_REGISTERED.equals(status)) { progressBar.setVisibility(View.INVISIBLE); updateUI("Registration SUCCEEDED", true); } else if (RegistrationConstants.UNREGISTER_CLIENT.equals(action) && RegistrationConstants.STATUS_UNREGISTERED.equals(status)) { token = ""; updateUI("Unregistration SUCCEEDED", false); showToast("Unregistered!"); } else { downstreamBundleView.setText(data.toString()); } } }; LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(RegistrationConstants.REGISTRATION_COMPLETE)); LocalBroadcastManager.getInstance(this).registerReceiver(mDownstreamBroadcastReceiver, new IntentFilter(RegistrationConstants.NEW_DOWNSTREAM_MESSAGE)); stringIdentifierField.setText("<a_name_to_recognize_the_device>"); }