List of usage examples for android.content Intent hasExtra
public boolean hasExtra(String name)
From source file:io.v.android.apps.syncslides.DeckChooserFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CODE_IMPORT_DECK: if (resultCode != Activity.RESULT_OK) { String errorStr = data != null && data.hasExtra(DocumentsContract.EXTRA_ERROR) ? data.getStringExtra(DocumentsContract.EXTRA_ERROR) : ""; toast("Error selecting deck to import " + errorStr); break; }/*from w w w. j a v a 2 s .c o m*/ Uri uri = data.getData(); importDeck(DocumentFile.fromTreeUri(getContext(), uri)); break; } }
From source file:com.appmanager.android.app.DetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); setupActionBar();/* w ww. j a va 2s . co m*/ mFileEntry = null; Intent intent = getIntent(); Button deleteButton = (Button) findViewById(R.id.delete); if (intent != null) { if (intent.hasExtra(EXTRA_FILE_ENTRY)) { mFileEntry = intent.getParcelableExtra(EXTRA_FILE_ENTRY); if (mFileEntry != null) { restoreValues(mFileEntry); } } else { ((EditText) findViewById(R.id.url)).setText(DEFAULT_URL); deleteButton.setEnabled(false); } } findViewById(R.id.download).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { confirmDownload(); } }); findViewById(R.id.save).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { save(); } }); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { confirmDelete(); } }); }
From source file:io.github.carlorodriguez.alarmon.AlarmClockService.java
private void handleStart(Intent intent) { if (intent != null && intent.hasExtra(COMMAND_EXTRA)) { Bundle extras = intent.getExtras(); int command = extras.getInt(COMMAND_EXTRA, COMMAND_UNKNOWN); final Handler handler = new Handler(); final Runnable maybeShutdown = new Runnable() { @Override//from w w w .j a va 2 s .co m public void run() { if (pendingAlarms.size() == 0) { stopSelf(); } } }; switch (command) { case COMMAND_NOTIFICATION_REFRESH: refreshNotification(); handler.post(maybeShutdown); break; case COMMAND_DEVICE_BOOT: fixPersistentSettings(); handler.post(maybeShutdown); break; case COMMAND_TIMEZONE_CHANGE: if (AppSettings.isDebugMode(getApplicationContext())) { Toast.makeText(getApplicationContext(), "TIMEZONE CHANGE, RESCHEDULING...", Toast.LENGTH_SHORT) .show(); } for (long alarmId : pendingAlarms.pendingAlarms()) { scheduleAlarm(alarmId); if (AppSettings.isDebugMode(getApplicationContext())) { Toast.makeText(getApplicationContext(), "ALARM " + alarmId, Toast.LENGTH_SHORT).show(); } } handler.post(maybeShutdown); break; default: throw new IllegalArgumentException("Unknown service command."); } } }
From source file:androidx.media.session.MediaButtonReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent == null || !Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction()) || !intent.hasExtra(Intent.EXTRA_KEY_EVENT)) { Log.d(TAG, "Ignore unsupported intent: " + intent); return;/*from www . j a v a2 s. co m*/ } ComponentName mediaButtonServiceComponentName = getServiceComponentByAction(context, Intent.ACTION_MEDIA_BUTTON); if (mediaButtonServiceComponentName != null) { intent.setComponent(mediaButtonServiceComponentName); startForegroundService(context, intent); return; } ComponentName mediaBrowserServiceComponentName = getServiceComponentByAction(context, MediaBrowserServiceCompat.SERVICE_INTERFACE); if (mediaBrowserServiceComponentName != null) { PendingResult pendingResult = goAsync(); Context applicationContext = context.getApplicationContext(); MediaButtonConnectionCallback connectionCallback = new MediaButtonConnectionCallback(applicationContext, intent, pendingResult); MediaBrowserCompat mediaBrowser = new MediaBrowserCompat(applicationContext, mediaBrowserServiceComponentName, connectionCallback, null); connectionCallback.setMediaBrowser(mediaBrowser); mediaBrowser.connect(); return; } throw new IllegalStateException("Could not find any Service that handles " + Intent.ACTION_MEDIA_BUTTON + " or implements a media browser service."); }
From source file:com.rosterloh.moodring.profile.BleProfileService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS)) throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key"); final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI); mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); Log.i(TAG, "Service started"); // notify user about changing the state to CONNECTING final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING); LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress); mDeviceName = device.getName();//from w ww .ja v a2 s. co m onServiceStarted(); Log.v(TAG, "Connecting..."); mBleManager.connect(BleProfileService.this, device); return START_REDELIVER_INTENT; }
From source file:com.tenforwardconsulting.cordova.bgloc.LocationService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "Received start id " + startId + ": " + intent); // config = Config.fromByteArray(intent.getByteArrayExtra("config")); if (intent.hasExtra("config")) { config = (Config) intent.getParcelableExtra("config"); } else {/*from w w w .ja v a 2 s. c o m*/ config = new Config(); } ServiceProviderFactory spf = new ServiceProviderFactory(this, config); provider = spf.getInstance(config.getServiceProvider()); provider.onCreate(); if (config.getStartForeground()) { // Build a Notification required for running service in foreground. NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(config.getNotificationTitle()); builder.setContentText(config.getNotificationText()); if (config.getSmallNotificationIcon() != null) { builder.setSmallIcon(getPluginResource(config.getSmallNotificationIcon())); } else { builder.setSmallIcon(android.R.drawable.ic_menu_mylocation); } if (config.getLargeNotificationIcon() != null) { builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(), getPluginResource(config.getLargeNotificationIcon()))); } if (config.getNotificationIconColor() != null) { builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor())); } setClickEvent(builder); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR; startForeground(startId, notification); } provider.startRecording(); //We want this service to continue running until it is explicitly stopped return START_REDELIVER_INTENT; }
From source file:com.samebits.beacon.locator.ui.fragment.TrackedBeaconsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == Constants.REQ_UPDATED_ACTION_BEACON) { if (data != null && data.hasExtra(Constants.ARG_ACTION_BEACON)) { ActionBeacon actionBeacon = data.getParcelableExtra(Constants.ARG_ACTION_BEACON); if (actionBeacon != null) { //TODO check if isDirty, now we store always even no changes if (mDataManager.updateBeaconAction(actionBeacon)) { mBeaconsAdapter.updateBeaconAction(actionBeacon); } else { //TODO error }/* w w w . j a v a 2s . c o m*/ } } } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.gbozza.android.stockhawk.ui.StockFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_stocks, container, false); ButterKnife.bind(this, rootView); mContext = getContext();/*from w w w. j a va 2 s . c o m*/ mAdapter = new StockAdapter(mContext, new StockAdapter.StockAdapterOnClickHandler() { @Override public void onClick(String symbol, StockAdapter.StockViewHolder vh) { ((Callback) getActivity()).onItemSelected(symbol, vh); } }); mStockRecyclerView.setAdapter(mAdapter); mStockRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); if (null != savedInstanceState) { manageError(); if (savedInstanceState.containsKey(BUNDLE_STOCK_KEY)) { ArrayList<StockParcelable> stockList = savedInstanceState.getParcelableArrayList(BUNDLE_STOCK_KEY); MatrixCursor matrixCursor = new MatrixCursor(DetailFragment.DETAIL_COLUMNS); getActivity().startManagingCursor(matrixCursor); for (StockParcelable stock : stockList) { matrixCursor.addRow(new Object[] { stock.getId(), stock.getSymbol(), stock.getPrice(), stock.getAbsolute_change(), stock.getPercentage_change(), stock.getHistory() }); } mAdapter.setCursor(matrixCursor); } } else { mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setRefreshing(true); Intent inboundIntent = getActivity().getIntent(); if (null != inboundIntent && !inboundIntent.hasExtra(ListWidgetService.EXTRA_LIST_WIDGET_SYMBOL)) { QuoteSyncJob.initialize(mContext, QuoteSyncJob.PERIODIC_ID); onRefresh(); } getActivity().getSupportLoaderManager().initLoader(STOCK_LOADER, null, this); } FloatingActionButton addStockFab = (FloatingActionButton) rootView.findViewById(R.id.fab); addStockFab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new AddStockDialog().show(getActivity().getSupportFragmentManager(), "StockDialogFragment"); } }); new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { String symbol = mAdapter.getSymbolAtPosition(viewHolder.getAdapterPosition()); PrefUtils.removeStock(mContext, symbol); mContext.getContentResolver().delete(Contract.Quote.makeUriForStock(symbol), null, null); } }).attachToRecyclerView(mStockRecyclerView); return rootView; }
From source file:it.mb.whatshare.SendToGCMActivity.java
@Override protected void onNewIntent(final Intent intent) { tracker = GoogleAnalytics.getInstance(this).getDefaultTracker(); if (intent.hasExtra(Intent.EXTRA_TEXT)) { if (!Utils.isConnectedToTheInternet(this)) { Dialogs.noInternetConnection(this, R.string.no_internet_sending, true); } else {// www .ja v a 2 s.co m // send to paired device if any try { if (outboundDevice == null) { Pair<PairedDevice, String> paired = loadOutboundPairing(this); if (paired != null) outboundDevice = paired.first; } if (outboundDevice != null) { // share with other device shareViaGCM(intent); finish(); return; } } catch (OptionalDataException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // can't load paired device from file tracker.sendEvent("intent", "send_to_gcm", "no_paired_device", 0L); Dialogs.noPairedDevice(this); } } else { // user clicked on the notification notificationCounter.set(0); finish(); } }
From source file:co.lmejia.iglesia.AssistanceListActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult"); Assistance assistance_new; String message = ""; if (requestCode == ASSISTANCE_REQUEST_CODE && data != null) { if (data.hasExtra(Assistance.TAG)) { assistance_new = (Assistance) data.getSerializableExtra(Assistance.TAG); if (resultCode == AssistanceActivity.RESULT_OK) { mAdapter.addItem(assistance_new, 0); message = "Se agreg una asistencia"; } else if (resultCode == AssistanceActivity.RESULT_EDIT) { mAdapter.updateItem(assistance_new, positionEdit); message = "Se modific una asistencia"; }//w w w . j a v a 2 s . co m Toast t = Toast.makeText(this, message, Toast.LENGTH_SHORT); t.show(); } } }