List of usage examples for android.content Intent getParcelableExtra
public <T extends Parcelable> T getParcelableExtra(String name)
From source file:de.damdi.fitness.activity.settings.sync.OpenTrainingSyncService.java
protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent()"); version = intent.getIntExtra(EXTRA_VERSION_CODE, -1); host = intent.getStringExtra(EXTRA_HOST); mReceiver = intent.getParcelableExtra("receiver"); String command = intent.getStringExtra("command"); Bundle b = new Bundle(); if (command.equals("query")) { try {/*from w w w .j ava2 s . co m*/ // set up REST-Client mClient = new RestClient(host, port, "https", version); // download and parse the exercises ArrayList<ExerciseType> allExercises = downloadAndParseExercises(); // add data to bundle b.putSerializable("all_exercises", allExercises); mReceiver.send(STATUS_FINISHED, b); } catch (Exception e) { Log.e(TAG, "Error, could not get exercises from server: " + e.toString(), e); b.putString(Intent.EXTRA_TEXT, e.toString()); mReceiver.send(STATUS_ERROR, b); } } this.stopSelf(); }
From source file:org.androidtitlan.estoesgoogle.service.SyncService.java
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")"); final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER); if (receiver != null) receiver.send(STATUS_RUNNING, Bundle.EMPTY); final SharedPreferences prefs = getSharedPreferences(Prefs.IOSCHED_SYNC, Context.MODE_PRIVATE); try {/*w ww .j a va 2 s. c om*/ // Bulk of sync work, performed by executing several fetches from // local sources. // Load static local data mLocalExecutor.execute(R.xml.blocks, new LocalBlocksHandler()); mLocalExecutor.execute(R.xml.speakers, new LocalSpeakersHandler()); mLocalExecutor.execute(R.xml.rooms, new LocalRoomsHandler()); mLocalExecutor.execute(R.xml.tracks, new LocalTracksHandler()); mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler()); mLocalExecutor.execute(R.xml.sessions, new LocalSessionsHandler()); // Save local parsed version prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit(); } catch (Exception e) { Log.e(TAG, "Problem while syncing", e); if (receiver != null) { // Pass back error to surface listener final Bundle bundle = new Bundle(); bundle.putString(Intent.EXTRA_TEXT, e.toString()); receiver.send(STATUS_ERROR, bundle); } } // Announce success to any surface listener Log.d(TAG, "sync finished"); if (receiver != null) receiver.send(STATUS_FINISHED, Bundle.EMPTY); }
From source file:com.microblink.ocr.MenuActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MY_REQUEST_CODE && resultCode == Activity.RESULT_OK) { // First, obtain recognition result RecognitionResults results = data.getParcelableExtra(ExtrasKeys.EXTRAS_RECOGNITION_RESULTS); showResults(results);/*from www . jav a 2s. c o m*/ } }
From source file:com.github.sryze.wirebug.MainActivity.java
@Override protected void onResume() { super.onResume(); boolean isConnected = NetworkUtils.isConnectedToWifi(connectivityManager); connectedView.setVisibility(isConnected ? View.VISIBLE : View.GONE); notConnectedView.setVisibility(isConnected ? View.GONE : View.VISIBLE); boolean isEnabled = DebugManager.isTcpDebuggingEnabled(); updateInstructions(isEnabled);//from w w w . j av a 2 s . c o m updateStatus(); toggleDebuggingButton.setOnCheckedChangeListener(null); toggleDebuggingButton.setChecked(isEnabled); toggleDebuggingButton.setOnCheckedChangeListener(enableSwitchChangeListener); networkStateChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received network state changed broadcast"); NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); switch (networkInfo.getState()) { case CONNECTED: connectedView.setVisibility(View.VISIBLE); notConnectedView.setVisibility(View.INVISIBLE); break; case DISCONNECTED: connectedView.setVisibility(View.GONE); notConnectedView.setVisibility(View.VISIBLE); break; } updateConnectionInfo(); } }; registerReceiver(networkStateChangedReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); debugStatusChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received debug state change broadcast"); boolean isEnabled = intent.getBooleanExtra(DebugStatusService.EXTRA_IS_ENABLED, false); updateInstructions(isEnabled); toggleDebuggingButton.setOnCheckedChangeListener(null); toggleDebuggingButton.setChecked(isEnabled); toggleDebuggingButton.setOnCheckedChangeListener(enableSwitchChangeListener); } }; registerReceiver(debugStatusChangedReceiver, new IntentFilter(DebugStatusService.ACTION_STATUS_CHANGED)); }
From source file:fr.eyal.lib.data.service.DataLibService.java
/** * Send the result of a request to the linked {@link ServiceHelper} * //www . j av a 2 s . c o m * @param request the request * @param response the response * @param code the status of the request */ protected void sendResult(final DataLibRequest request, final BusinessResponse response, final int code) { Out.d(TAG, "sendResult"); final Intent intent = request.intent; final ResultReceiver receiver = (ResultReceiver) intent.getParcelableExtra(INTENT_EXTRA_RECEIVER); if (receiver != null) { final Bundle b = new Bundle(); if (response != null && response.response != null) { //if the Business Object have to be transmit inside the Bundle if (request.isParcelableMethodEnabled()) b.putParcelable(ServiceHelper.RECEIVER_EXTRA_RESULT, response.response); //we add the request id to the response if (response.response instanceof ResponseBusinessObjectDAO) { ResponseBusinessObjectDAO r = (ResponseBusinessObjectDAO) response.response; b.putLong(ServiceHelper.RECEIVER_EXTRA_RESULT_ID, r._id); } else { //in case of no data cache, we set an invalid ID b.putLong(ServiceHelper.RECEIVER_EXTRA_RESULT_ID, BusinessObjectDAO.ID_INVALID); } } else { Out.e(TAG, "Unfined response"); } //we copy the content of the response in the intent's bundle b.putInt(ServiceHelper.RECEIVER_EXTRA_REQUEST_ID, intent.getIntExtra(INTENT_EXTRA_REQUEST_ID, -1)); b.putInt(ServiceHelper.RECEIVER_EXTRA_WEBSERVICE_TYPE, intent.getIntExtra(INTENT_EXTRA_PROCESSOR_TYPE, -1)); b.putInt(ServiceHelper.RECEIVER_EXTRA_RETURN_CODE, response.returnCode); b.putInt(ServiceHelper.RECEIVER_EXTRA_RESULT_CODE, response.status); b.putString(ServiceHelper.RECEIVER_EXTRA_RESULT_MESSAGE, ""); receiver.send(code, b); } }
From source file:com.meetingninja.csse.user.ProfileFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == 7) { displayedUser = ((UserParcel) data.getParcelableExtra(Keys.User.PARCEL)).getUser(); setUser(displayedUser);// ww w . j av a 2 s .c om } } }
From source file:com.gbaldera.tipaypal.TipaypalModule.java
@Override public void onResult(Activity activity, int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION); if (confirm != null) { try { // send 'confirm' to your server for verification. // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ // for more details. Log.i(TAG, confirm.toJSONObject().toString(4)); processResult(resultCode, new KrollDict(confirm.toJSONObject())); } catch (JSONException e) { processFailed(resultCode, e); }//from www .ja va 2 s .com } } else if (resultCode == Activity.RESULT_CANCELED) { processCanceled(resultCode); } else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) { processInvalid(resultCode); } }
From source file:com.lambdasoup.quickfit.persist.FitApiFailureResolutionService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (!intent.hasExtra(EXTRA_FAILURE_RESULT)) { throw new IllegalArgumentException("Required extra " + EXTRA_FAILURE_RESULT + " missing."); }/* w w w . j av a2s . co m*/ ConnectionResult connectionResult = intent.getParcelableExtra(EXTRA_FAILURE_RESULT); if (isBound && currentForegroundResolver != null) { handleErrorInForeground(connectionResult, startId); } else { handleErrorInBackground(connectionResult, startId); } return START_REDELIVER_INTENT; }
From source file:com.ryan.ryanreader.activities.PostListingActivity.java
public void onCreate(final Bundle savedInstanceState) { PrefsUtility.applyTheme(this); // TODO load from savedInstanceState getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getWindow().setBackgroundDrawable(new ColorDrawable(getSupportActionBarContext() .obtainStyledAttributes(new int[] { R.attr.rrListBackgroundCol }).getColor(0, 0))); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); sharedPreferences.registerOnSharedPreferenceChangeListener(this); RedditAccountManager.getInstance(this).addUpdateListener(this); if (getIntent() != null) { final Intent intent = getIntent(); if (intent.hasExtra("subreddit")) { subreddit = intent.getParcelableExtra("subreddit"); controller = new PostListingControllerSubreddit(subreddit); if (subreddit.isReal()) { OptionsMenuUtility.fixActionBar(this, subreddit.url); } else { OptionsMenuUtility.fixActionBar(this, subreddit.title); }/* www .j a va 2 s . co m*/ } else { throw new RuntimeException("No subreddit provided"); } super.onCreate(savedInstanceState); setContentView(R.layout.main_single); requestRefresh(RefreshableFragment.POSTS, false); } else { throw new RuntimeException("Nothing to show! (should load from bundle)"); // TODO } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.services.WebRequestService.java
@Override protected void onHandleIntent(Intent intent) { EventTransformationRequest request = intent.getParcelableExtra(Event.PARCELABLE_EXTRA_EVENT); if (D)//from www . j a v a 2 s. co m Log.d(TAG, "Receiving web request for transformation to type: " + request.getEventSubscription()); // create JSON object for querying the server JSONArray advertisedEventTypes = new JSONArray(convertArrayToList(request.getAdvertisedEvents())); JSONObject jsonRequestString = new JSONObject(); try { jsonRequestString.put(JSON_AVAILABLE_EVENT_TYPES, advertisedEventTypes); jsonRequestString.put(JSON_REQUESTED_EVENT_TYPE, request.getEventSubscription()); } catch (JSONException ex) { ex.printStackTrace(); } // Build server address SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(this); String host = spref.getString(Preferences.TM_REMOTE_REPOSITORY_HOST, "192.168.1.7"); int port = Integer.valueOf(spref.getString(Preferences.TM_REMOTE_REPOSITORY_PORT, "8080")); String baseUrl = "http://" + host + ":" + port; // Build URI Uri.Builder b = Uri.parse(baseUrl).buildUpon(); b.path("/transformators/query/"); b.appendQueryParameter("jsonString", jsonRequestString.toString()); String urlRequest = b.build().toString(); if (D) Log.d(TAG, "Send request to: " + urlRequest); // Request server String serverResponse = null; HttpClient httpClient = new DefaultHttpClient(); boolean connectionFailure = false; boolean transformationFound = false; try { // generate httpGet HttpGet httpGet = new HttpGet(urlRequest); // headers httpGet.setHeader("Accept", "application/json"); httpGet.setHeader("Content-Type", "application/json"); // execute request HttpResponse response = httpClient.execute(httpGet); // process response StatusLine statusLine = response.getStatusLine(); if (D) Log.d(TAG, "Server response status " + statusLine); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { // read response transformationFound = true; ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); serverResponse = out.toString(); } else if (statusLine.getStatusCode() == HttpStatus.SC_NO_CONTENT) { if (D) Log.i(TAG, "no transformation found"); transformationFound = false; } // catch exceptions } catch (ClientProtocolException ex) { ex.printStackTrace(); connectionFailure = true; } catch (IOException ex) { ex.printStackTrace(); connectionFailure = true; } // Generate response to TransformationManager and FelixService // Connection failed if (connectionFailure) { if (D) Log.d(TAG, "Notifying a failed request"); // TODO do we want to transmit a connection error? EventTransformationResponse reponse = new EventTransformationResponse("todo", "todo", TAG, request.getID(), false); sendToChannel(reponse, AbstractChannel.LOCAL_MANAGEMENT); // Connection successful } else { // no transformation found if (!transformationFound) { if (D) Log.d(TAG, "No transformation available"); EventTransformationResponse reponse = new EventTransformationResponse("todo", "todo", TAG, request.getID(), false); sendToChannel(reponse, AbstractChannel.LOCAL_MANAGEMENT); // transformation found } else { if (D) Log.d(TAG, "Transformation available"); // generate Intent for felix service Intent i = new Intent(); // add EventTRansformationResponse EventTransformationResponse reponse = new EventTransformationResponse("todo", "todo", TAG, request.getID(), true); i.putExtra(Event.PARCELABLE_EXTRA_EVENT, reponse); i.putExtra(Event.PARCELABLE_EXTRA_EVENT_TYPE, reponse.getEventType()); // add server response i.putExtra(FelixService.INTENT_EXTRA_TRANSFORMATION_BYTE_CODE, serverResponse); // successful requests are first forwarded to the felix service i.setAction(FelixService.FELIX_SUCCESSFUL_WEB_REQUEST); LocalBroadcastManager.getInstance(this).sendBroadcast(i); } } }