Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

In this page you can find the example usage for android.content Intent hasExtra.

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:de.j4velin.encrypter.EncryptedFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_OUTPUT) {
            String expectedFilename;
            if (data.hasExtra(Intent.EXTRA_TITLE)) {
                expectedFilename = data.getStringExtra(Intent.EXTRA_TITLE);
            } else {
                expectedFilename = selectedFile.name;
            }/*from   ww w.j  ava 2s .  c  o  m*/
            try {
                CryptoUtil.decrypt(getContext(), selectedFile, data.getData(), expectedFilename);
            } catch (GeneralSecurityException e) {
                Snackbar.make(((MainActivity) getActivity()).getCoordinatorLayout(),
                        getString(R.string.error_security, e.getMessage()), Snackbar.LENGTH_LONG).show();
            } catch (FileNotFoundException e) {
                Snackbar.make(((MainActivity) getActivity()).getCoordinatorLayout(),
                        R.string.error_file_not_found, Snackbar.LENGTH_LONG).show();
            } catch (IOException e) {
                Snackbar.make(((MainActivity) getActivity()).getCoordinatorLayout(),
                        getString(R.string.error_io, e.getMessage()), Snackbar.LENGTH_LONG).show();
            }
        }
    }
}

From source file:com.szanata.cordova.plugins.PhoneStateChangeListener.java

/**
 * creates a new BroadcastReceiver to listen whether the Telephony State changes
 *//*w w w.  jav  a  2  s . c  o  m*/
public void startPhoneListener() {

    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(final Context context, final Intent intent) {

                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    String state = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : NONE;
                    String number = "";

                    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    }
                    if (callbackContext != null) {
                        final JSONObject data = new JSONObject();
                        try {
                            data.put("state", state);
                            data.put("number", number);
                        } catch (final JSONException e) {
                        }
                        ;
                        callbackContext.success(data);
                    }
                }
            }
        };

        this.context.registerReceiver(this.receiver,
                new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
    }
}

From source file:com.deliciousdroid.fragment.MainSearchResultsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    base = (FragmentBaseActivity) getActivity();
    base.setTitle(R.string.main_search_results_title);

    String[] MENU_ITEMS = new String[] { getString(R.string.search_results_bookmark),
            getString(R.string.search_results_tag), getString(R.string.search_results_global_tag) };

    setListAdapter(new ArrayAdapter<String>(base, R.layout.main_view, MENU_ITEMS));

    final Intent intent = base.getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(base, MainSearchResultsFragment.class);
            i.putExtras(intent.getExtras());
            startActivity(i);//from  w ww.j  ava  2 s  .  c  o  m
            base.finish();
        } else {
            base.onSearchRequested();
        }
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);

            startActivity(i);
            base.finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())) {
            Intent viewBookmark = new Intent(base, ViewBookmark.class);
            viewBookmark.setData(data);

            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            base.finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(base, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            base.finish();
        }
    }

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                searchActionListener.onBookmarkSearch();
            } else if (position == 1) {
                searchActionListener.onTagSearch();
            } else if (position == 2) {
                searchActionListener.onGlobalTagSearch();
            }
        }
    });
}

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);
            }/*from   www.j  a v  a 2s  . c om*/

        } 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:com.pindroid.activity.SaveReadLaterBookmark.java

private void handleIntent() {
    if (app.getUsername() != null) {
        Intent intent = getIntent();

        if ((Intent.ACTION_SEND.equals(intent.getAction())
                || Constants.ACTION_READLATER.equals(intent.getAction()))
                && intent.hasExtra(Intent.EXTRA_TEXT)) {
            ShareCompat.IntentReader reader = ShareCompat.IntentReader.from(this);
            String url = StringUtils.getUrl(reader.getText().toString());

            if ("".equals(url)) {
                Toast.makeText(this, R.string.add_bookmark_invalid_url, Toast.LENGTH_LONG).show();
                finish();/*  w  w  w. j av  a  2 s .  com*/
            } else {
                saveBookmark(intent, reader, url);
            }
        }
    } else {
        Toast.makeText(this, R.string.login_no_account, Toast.LENGTH_SHORT).show();
        finish();
    }
}

From source file:com.linroid.pushapp.service.DownloadService.java

@DebugLog
@Override//from www.j  a  v  a  2  s .c o  m
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null || !intent.hasExtra(EXTRA_PACKAGE)) {
        //            throw new IllegalArgumentException("require push info extra");
        Timber.e("require package info extra");
        return super.onStartCommand(intent, flags, startId);
    }
    Timber.d("Bundle: %s", AndroidUtil.sprintBundle(intent.getExtras()));
    Pack pack = intent.getParcelableExtra(EXTRA_PACKAGE);
    newDownloadTask(pack);
    return super.onStartCommand(intent, flags, startId);
}

From source file:com.zion.htf.ui.ArtistDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.actionBar = this.getSupportActionBar();

    Intent openingIntent = this.getIntent();
    try {/*from   w  w w  . ja  va  2 s .  com*/
        Bundle args = new Bundle(1);

        if (openingIntent.hasExtra(ArtistDetailsActivity.EXTRA_SET_ID)) {
            args.putInt(ArtistDetailsFragment.ARG_SET_ID,
                    openingIntent.getIntExtra(ArtistDetailsActivity.EXTRA_SET_ID, 0));
            args.putInt(ArtistSoundcloudFragment.ARG_SET_ID,
                    openingIntent.getIntExtra(ArtistDetailsActivity.EXTRA_SET_ID, 0));
        } else if (openingIntent.hasExtra(ArtistDetailsActivity.EXTRA_ARTIST_ID)) {
            args.putInt(ArtistDetailsFragment.ARG_ARTIST_ID,
                    openingIntent.getIntExtra(ArtistDetailsActivity.EXTRA_ARTIST_ID, 0));
            args.putInt(ArtistSoundcloudFragment.ARG_ARTIST_ID,
                    openingIntent.getIntExtra(ArtistDetailsActivity.EXTRA_ARTIST_ID, 0));
        } else {
            throw new MissingArgumentException(String.format(Locale.ENGLISH,
                    "Either %s or %s is required for this Activity to work properly. Please provide any of them.",
                    ArtistDetailsFragment.ARG_SET_ID, ArtistDetailsFragment.ARG_ARTIST_ID));
        }

        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
        if (pref.getBoolean(this.getString(R.string.pref_key_other_enable_soundcloud_player), true)) {
            this.setContentView(R.layout.activity_artist_details);
            this.pagerAdapter = new ArtistDetailsPagerAdapter(this.getSupportFragmentManager(), args);
            this.viewPager = (ViewPager) this.findViewById(R.id.artist_details_pager);

            this.initViewPager();
            this.initTabs();
        } else {
            this.setContentView(R.layout.activity_artist_details_no_souncloud);

            FragmentManager fragmentManager = this.getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

            ArtistDetailsFragment artistDetailsFragment = new ArtistDetailsFragment();
            artistDetailsFragment.setArguments(args);

            fragmentTransaction.add(R.id.artist_details_empty_layout, artistDetailsFragment);
            fragmentTransaction.commit();
        }
    } catch (MissingArgumentException e) {
        if (BuildConfig.DEBUG)
            e.printStackTrace();
        throw new RuntimeException(e);
        // Report this through piwik
    }
}

From source file:com.sonnychen.aviationhk.LightboxActivity.java

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

    // go full screen
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    Intent intent = getIntent();
    if (intent == null || (!intent.hasExtra(INTENT_URLS_PARAM))) {
        finish();/*from  ww w.  j a va2  s  .c  o m*/
        return;
    }

    setContentView(R.layout.activity_lightbox);

    // load images from intent
    mURLs = intent.getStringArrayListExtra(INTENT_URLS_PARAM);
    mLightBox = (ExtendedViewPager) findViewById(R.id.lightbox);
    mImagesAdapter = new ImagesAdapter();
    mLightBox.setAdapter(mImagesAdapter);
    mLightBox.setCurrentItem(intent.getIntExtra(INTENT_INDEX_PARAM, 0));

    Log.v(INTENT_URLS_PARAM, mURLs.toString());
    Log.v(INTENT_INDEX_PARAM, mURLs.toString());
}

From source file:com.pokescanner.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (data == null || !data.hasExtra(GoogleLoginActivity.EXTRA_CODE)) {
        showToast(R.string.AUTH_FAILED);
        return;/*  w  ww  .  java 2s  .c om*/
    }
    String code = data.getStringExtra(GoogleLoginActivity.EXTRA_CODE);
    if (code != null) {
        AuthGOOGLELoader authGOOGLELoader = new AuthGOOGLELoader(code);
        authGOOGLELoader.start();
    } else {
        showToast(R.string.AUTH_FAILED);
    }
}

From source file:ch.ethz.twimight.activities.HomeScreenActivity.java

private void setSelectedTab(Intent intent) {
    int initialPosition = 0;
    if (intent.hasExtra(EXTRA_KEY_INITIAL_TAB)) {
        String initialTab = intent.getStringExtra(EXTRA_KEY_INITIAL_TAB);

        if (EXTRA_INITIAL_TAB_TIMELINE.equals(initialTab)) {
            initialPosition = 0;/*  w  w w .j av a2s.  c om*/
        } else if (EXTRA_INITIAL_TAB_FAVORITES.equals(initialTab)) {
            initialPosition = 1;
        } else if (EXTRA_INITIAL_TAB_MENTIONS.equals(initialTab)) {
            initialPosition = 2;
        }
        intent.removeExtra(EXTRA_KEY_INITIAL_TAB);
    }
    mViewPager.setCurrentItem(initialPosition);
    setFragment(initialPosition);
}