Java Code Examples for android.content.Intent#hasExtra()

The following examples show how to use android.content.Intent#hasExtra() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailActivity.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    mWeatherDisplay = (TextView) findViewById(R.id.tv_display_weather);

    Intent intentThatStartedThisActivity = getIntent();

    if (intentThatStartedThisActivity != null) {
        if (intentThatStartedThisActivity.hasExtra(Intent.EXTRA_TEXT)) {
            mForecast = intentThatStartedThisActivity.getStringExtra(Intent.EXTRA_TEXT);
            mWeatherDisplay.setText(mForecast);
        }
    }
}
 
Example 2
Source File: Luhn.java    From Luhn with MIT License 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CARDIO_REQUEST_ID) {
        if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
            CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);

            cardNumber.getEditText().setText(scanResult.getFormattedCardNumber());
            if (scanResult.isExpiryValid()) {
                String month = String.valueOf(scanResult.expiryMonth).length() == 1 ? "0" + scanResult.expiryMonth : String.valueOf(scanResult.expiryMonth);
                String year = String.valueOf(scanResult.expiryYear).substring(2);
                expiryInputLayout.getEditText().setText(month + "/" + year);
            }

            if (scanResult.cvv != null) {
                // Never log or display a CVV
                cvvInputLayout.getEditText().setText(scanResult.cvv);
            }

        }
    }
}
 
Example 3
Source File: ReadabilityActivity.java    From Ninja with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.readability);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    progressBar = (ProgressBar) findViewById(R.id.readability_progress);
    webView = (WebView) findViewById(R.id.readability_webview);
    emptyView = (TextView) findViewById(R.id.readability_empty);
    showLoadStart();

    sp = PreferenceManager.getDefaultSharedPreferences(this);
    int color = sp.getInt(getString(R.string.sp_readability_background), getResources().getColor(R.color.white));
    findViewById(R.id.readability_frame).setBackgroundColor(color);

    String token = sp.getString(getString(R.string.sp_readability_token), null);
    Intent intent = getIntent();
    if (intent == null || !intent.hasExtra(IntentUnit.URL) || token == null || token.trim().isEmpty()) {
        showLoadError();
    } else {
        String url = intent.getStringExtra(IntentUnit.URL);
        query = REQUEST.replace(REQUEST_URL, url).replace(REQUEST_TOKEN, token);
        new ReadabilityTask(this, query).execute();
    }
}
 
Example 4
Source File: QRCodeEncoder.java    From android-apps with MIT License 6 votes vote down vote up
private void encodeContentsFromShareIntentPlainText(Intent intent) throws WriterException {
  // Notice: Google Maps shares both URL and details in one text, bummer!
  String theContents = ContactEncoder.trim(intent.getStringExtra(Intent.EXTRA_TEXT));
  // We only support non-empty and non-blank texts.
  // Trim text to avoid URL breaking.
  if (theContents == null || theContents.length() == 0) {
    throw new WriterException("Empty EXTRA_TEXT");
  }
  contents = theContents;
  // We only do QR code.
  format = BarcodeFormat.QR_CODE;
  if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
    displayContents = intent.getStringExtra(Intent.EXTRA_SUBJECT);
  } else if (intent.hasExtra(Intent.EXTRA_TITLE)) {
    displayContents = intent.getStringExtra(Intent.EXTRA_TITLE);
  } else {
    displayContents = contents;
  }
  title = activity.getString(R.string.contents_text);
}
 
Example 5
Source File: NetworkBrowserFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null){
        String mrl = savedInstanceState.getString(BaseBrowserFragment.KEY_MRL);
        if (mrl != null)
            mUri = Uri.parse(mrl);
        mItemSelected = savedInstanceState.getParcelable(SELECTED_ITEM);
    } else {
        Intent intent = getActivity().getIntent();
        if (intent != null && intent.hasExtra(BaseBrowserFragment.KEY_MRL))
            mUri = Uri.parse(intent.getStringExtra(BaseBrowserFragment.KEY_MRL));
    }
    setOnItemViewClickedListener(this);
    setOnItemViewSelectedListener(this);
    setAdapter(mAdapter);

    // UI setting
    setHeadersState(HEADERS_ENABLED);
    setBrandColor(getResources().getColor(R.color.orange800));
}
 
Example 6
Source File: MultiredditOverview.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 940 && adapter != null && adapter.getCurrentFragment() != null) {
        if (resultCode == RESULT_OK) {
            LogUtil.v("Doing hide posts");
            ArrayList<Integer> posts = data.getIntegerArrayListExtra("seen");
            ((MultiredditView) adapter.getCurrentFragment()).adapter.refreshView(posts);
            if (data.hasExtra("lastPage")
                    && data.getIntExtra("lastPage", 0) != 0
                    && ((MultiredditView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager) {
                ((LinearLayoutManager) ((MultiredditView) adapter.getCurrentFragment()).rv.getLayoutManager())
                        .scrollToPositionWithOffset(data.getIntExtra("lastPage", 0) + 1,
                                mToolbar.getHeight());
            }
        } else {
            ((MultiredditView) adapter.getCurrentFragment()).adapter.refreshView();
        }
    }

}
 
Example 7
Source File: NotificationsService.java    From bitseal with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent)
{
	if (intent.hasExtra(EXTRA_NEW_MESSAGES_NOTIFICATION_CLEARED))
	{
		// Set the 'new messages notification currently displayed' shared preference to false
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
		SharedPreferences.Editor editor = prefs.edit();
	    editor.putBoolean(KEY_NEW_MESSAGES_NOTIFICATION_CURRENTLY_DISPLAYED, false);
	    editor.commit();
	    
	    Log.i(TAG, "Recorded dismissal of new messages notification");
	}
	else if (intent.hasExtra(EXTRA_DISPLAY_NEW_MESSAGES_NOTIFICATION))
	{
		int newMessages = intent.getExtras().getInt(EXTRA_DISPLAY_NEW_MESSAGES_NOTIFICATION);
		
		displayNewMessagesNotification(newMessages);
	}
	else if (intent.hasExtra(EXTRA_DISPLAY_UNLOCK_NOTIFICATION))
	{
		displayUnlockNotification();
	}
}
 
Example 8
Source File: ExternalApiReceiver.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (!intent.hasExtra(AndroidSharedKeyRecord.EXTRA_KEY_ID)) {
        return;
    }

    String keyId = intent.getStringExtra(AndroidSharedKeyRecord.EXTRA_KEY_ID);
    SqlStorage<AndroidSharedKeyRecord> storage = CommCareApplication.instance().getGlobalStorage(AndroidSharedKeyRecord.class);
    AndroidSharedKeyRecord sharingKey;
    try {
        sharingKey = storage.getRecordForValue(AndroidSharedKeyRecord.META_KEY_ID, keyId);
    } catch (NoSuchElementException nsee) {
        //No valid key record;
        return;
    }

    Bundle b = sharingKey.getIncomingCallout(intent);

    performAction(context, b);
}
 
Example 9
Source File: FabTransform.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link FabTransform} from the supplied {@code activity} extras and set as its
 * shared element enter/return transition.
 */
public static boolean setup(@NonNull Activity activity, @Nullable View target) {
    final Intent intent = activity.getIntent();
    if (!intent.hasExtra(EXTRA_FAB_COLOR) || !intent.hasExtra(EXTRA_FAB_ICON_RES_ID)) {
        return false;
    }

    final int color = intent.getIntExtra(EXTRA_FAB_COLOR, Color.TRANSPARENT);
    final int icon = intent.getIntExtra(EXTRA_FAB_ICON_RES_ID, -1);
    final FabTransform sharedEnter = new FabTransform(color, icon);
    if (target != null) {
        sharedEnter.addTarget(target);
    }
    activity.getWindow().setSharedElementEnterTransition(sharedEnter);
    return true;
}
 
Example 10
Source File: LabelManagerPackageActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.label_manager_labels);

  final Intent intent = getIntent();
  if (!intent.hasExtra(EXTRA_PACKAGE_NAME)) {
    throw new IllegalArgumentException("Intent missing package name extra.");
  }

  packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);

  final PackageManager packageManager = getPackageManager();
  CharSequence applicationLabel;
  Drawable packageIcon;
  try {
    packageIcon = packageManager.getApplicationIcon(packageName);
    final PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
    applicationLabel = packageManager.getApplicationLabel(packageInfo.applicationInfo);
  } catch (NameNotFoundException e) {
    LogUtils.i(TAG, "Could not load package info for package %s.", packageName);

    packageIcon = packageManager.getDefaultActivityIcon();
    applicationLabel = packageName;
  }

  setTitle(getString(R.string.label_manager_package_title, applicationLabel));

  final ActionBar actionBar = getSupportActionBar();
  actionBar.setIcon(packageIcon);
  actionBar.setDisplayHomeAsUpEnabled(true);

  labelList = (ListView) findViewById(R.id.label_list);
  labelProviderClient = new LabelProviderClient(this, LabelProvider.AUTHORITY);
}
 
Example 11
Source File: HTMLViewerActivity.java    From BonjourBrowser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_html_viewer);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mWebView = findViewById(R.id.webview);
    mLoading = findViewById(R.id.loading);

    mWebView.setWebChromeClient(new ChromeClient());
    mWebView.setWebViewClient(new ViewClient());

    WebSettings s = mWebView.getSettings();
    s.setUseWideViewPort(true);
    s.setSupportZoom(true);
    s.setBuiltInZoomControls(true);
    s.setDisplayZoomControls(false);
    s.setSavePassword(false);
    s.setSaveFormData(false);
    s.setBlockNetworkLoads(true);

    // Javascript is purposely disabled, so that nothing can be
    // automatically run.
    s.setJavaScriptEnabled(false);
    s.setDefaultTextEncodingName("utf-8");

    final Intent intent = getIntent();
    if (intent.hasExtra(Intent.EXTRA_TITLE)) {
        setTitle(intent.getStringExtra(Intent.EXTRA_TITLE));
    }

    mWebView.loadUrl(String.valueOf(intent.getData()));
}
 
Example 12
Source File: VideoProcessingService.java    From patrol-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent: start process video service");

    DatabasePatrol db = DatabasePatrol.get(this);

    // add new video to db if need
    if (intent.hasExtra(VideoCaptureActivity.MOVIES_TO_SAVE)) {
        addVideo(intent);
    }

    //delete video
    else if (intent.hasExtra(DELETE_MOVIE)) {
        deleteVideo(intent);
    }

    //process all videos
    else {
        ArrayList<VideoItem> videoItems = db.getVideos(
                VideoItem.State.SAVING,
                ProjectPreferencesManager.getUser(this));

        if (!videoItems.isEmpty()) {
            for (VideoItem item : videoItems) {
                tryToProcessVideo(item, db);
            }
        }
    }

    // start auto upload service if need
    if (ProjectPreferencesManager.getAutoUploadMode(getApplicationContext())) {
        startService(new Intent(VideoProcessingService.this, UploadService.class));
    }
}
 
Example 13
Source File: BaseActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void filterIntent() {
    Intent intent = getIntent();
    if (intent != null) {
        if (intent.hasExtra(TradeInfo.TRADE_KEY)) {
            this.mTradeInfo = this.mTradeManager.getTradeInfo(intent.getStringExtra(TradeInfo.TRADE_KEY));
        }
        if (intent.hasExtra("state")) {
            this.mState = intent.getIntExtra("state", 0);
        }
        if (this.mState == 0) {
            LOG.logI("Activity Leak of Status");
        }
    }
}
 
Example 14
Source File: EventsBus.java    From deprecated-event-bus with Apache License 2.0 5 votes vote down vote up
@Override
public final void onReceive(Context context, Intent intent) {
    if (intent.hasExtra(EXTRA_EVENT_ID)) {
        Bundle params = intent.getExtras();
        String targetReceiverId = params.getString(EXTRA_RECEIVER_ID);

        if (targetReceiverId == null || targetReceiverId.equals(mReceiverId)) {
            mListener.onEvent(params.getInt(EXTRA_EVENT_ID), params, targetReceiverId == null);
        }
    }
}
 
Example 15
Source File: WifiPeriodicReplicationReceiverTest.java    From sync-android with Apache License 2.0 5 votes vote down vote up
@Override
public ComponentName startService(Intent service) {
    mIntentsReceived.add(service);
    if (service.hasExtra("android.support.content.wakelockid")) {
        return null;
    } else {
        return new ComponentName("mock.package.name", "MockClassName");
    }
}
 
Example 16
Source File: QuickRecordTile.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onBroadcastReceived(Context context, Intent intent) {
    super.onBroadcastReceived(context, intent);

    if (intent.getAction().equals(GravityBoxSettings.ACTION_PREF_QUICKSETTINGS_CHANGED)) {
        if (intent.hasExtra(GravityBoxSettings.EXTRA_QR_QUALITY)) {
            mAudioQuality = intent.getIntExtra(GravityBoxSettings.EXTRA_QR_QUALITY,
                    RecordingService.DEFAULT_SAMPLING_RATE);
        }
        if (intent.hasExtra(GravityBoxSettings.EXTRA_QR_AUTOSTOP)) {
            mAutoStopDelay = intent.getIntExtra(GravityBoxSettings.EXTRA_QR_AUTOSTOP, 1) * 3600000;
        }
    }
}
 
Example 17
Source File: MarketDetailActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.slide_in_right, 0);
    Intent intent = getIntent();
    if (intent != null && intent.hasExtra(BitherSetting.INTENT_REF.MARKET_INTENT)) {
        marketType = (MarketType) intent.getSerializableExtra(BitherSetting.INTENT_REF
                .MARKET_INTENT);
    }
    boolean isFromNotif = false;
    if (intent != null && intent.hasExtra(BitherSetting.INTENT_REF.INTENT_FROM_NOTIF)) {
        isFromNotif = intent.getBooleanExtra(BitherSetting.INTENT_REF.INTENT_FROM_NOTIF, false);
    }

    if (marketType == null) {
        finish();
    } else {
        setContentView(R.layout.activity_market_detail);
        initView();
        if (isFromNotif && BitherApplication.hotActivity != null) {
            chartKline.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (BitherApplication.hotActivity != null) {
                        BitherApplication.hotActivity.notifPriceAlert(marketType);
                    }
                }
            }, 500);

        }
    }
}
 
Example 18
Source File: SoundService.java    From volume_control_android with MIT License 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    String action = intent != null ? intent.getAction() : null;

    if (!DNDModeChecker.isDNDPermissionGranted(this) && !STOP_ACTION.equals(action)) {
        Toast.makeText(this, getString(R.string.dnd_permission_title), Toast.LENGTH_LONG).show();
        return super.onStartCommand(intent, flags, startId);
    }

    if (APPLY_PROFILE_ACTION.equals(action)) {
        try {
            SoundProfile profile = soundProfileStorage.loadById(intent.getIntExtra(PROFILE_ID, -1));
            ProfileApplier.applyProfile(control, profile);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        registerListeners(profilesToShow);
        startForeground();
        return super.onStartCommand(intent, flags, startId);
    } else if (STOP_ACTION.equals(action)) {
        stopForeground(true);
        notificationManagerCompat.cancel(
                staticNotificationNumber
        );
        stop(startId);
        isForeground = false;
        return super.onStartCommand(intent, flags, startId);
    } else if (CHANGE_VOLUME_ACTION.equals(action)) {
        int type = intent.getIntExtra(EXTRA_TYPE, 0);
        if (intent.hasExtra(EXTRA_VOLUME)) {
            int volume = intent.getIntExtra(EXTRA_VOLUME, 0);
            control.setVolumeLevel(type, volume);
        } else {
            float delta = intent.getFloatExtra(EXTRA_VOLUME_DELTA, 0);
            int currentVolume = control.getLevel(type);
            int nextVolume = (int) (delta > 0 ? Math.ceil(currentVolume + delta) : Math.floor(currentVolume + delta));
            control.setVolumeLevel(type, nextVolume);
        }
        registerListeners(profilesToShow);
        startForeground();
        return START_STICKY;
    } else if (FOREGROUND_ACTION.equals(action)) {
        createStaticNotificationChannel();
        showProfiles = intent.getBooleanExtra(EXTRA_SHOW_PROFILES, true);
        profilesToShow = (List<Integer>) intent.getSerializableExtra(EXTRA_VOLUME_TYPES_IDS);
        registerListeners(profilesToShow);
        startForeground();
        return START_NOT_STICKY;
    } else {
        return super.onStartCommand(intent, flags, startId);
    }
}
 
Example 19
Source File: SectionActivity.java    From Villains-and-Heroes with Apache License 2.0 4 votes vote down vote up
public static int getPosition(int resultCode, Intent data) {
    if (resultCode == RESULT_OK && data != null && data.hasExtra(EXTRA_POSITION)) {
        return data.getIntExtra(EXTRA_POSITION, EXTRA_NOT_FOUND);
    }
    return EXTRA_NOT_FOUND;
}
 
Example 20
Source File: MusicService.java    From vk_music_android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (intent != null && intent.hasExtra(KEY_ACTION)) {
        switch (intent.getIntExtra(KEY_ACTION, 0)) {
            case ACTION_PLAY_PAUSE:
                playPause();
                break;

            case ACTION_PREVIOUS:
                playPreviousTrackInQueue();
                break;

            case ACTION_NEXT:
                playNextTrackInQueue();
                break;

            case ACTION_DISMISS:
                mediaPlayer.stop();
                notificationManager.destroyNotification();

                for (MusicServiceListener listener : listeners) {
                    listener.onFinishRequested();
                }

                stopSelf();
                break;

            case ACTION_OPEN_ACTIVITY:
                if (listeners.size() == 0) {
                    Intent mainActivityIntent = new Intent(this, MainActivity.class);
                    mainActivityIntent.putExtra(MainActivity.KEY_INITIAL_FRAGMENT, MainActivity.FRAG_NOW_PLAYING);
                    mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                    startActivity(mainActivityIntent);
                }
                break;

            case ACTION_ADD:
                final VKApiAudio audio = currentAudio.get();
                VKApi.audio().add(VKParameters.from("audio_id", audio.id, "owner_id", audio.owner_id)).executeWithListener(new VKRequest.VKRequestListener() {
                    @Override
                    public void onComplete(VKResponse response) {
                        notificationManager.showAddCompleteIndicator();
                    }
                });
                break;
        }
    }

    return START_STICKY;
}