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:com.example.plugin.PhoneListener.java

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    this.phoneListenerCallbackId = null;
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override//from  w w  w.  jav  a 2s.  co  m
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
        this.registered = true;
    }

}

From source file:com.meiste.greg.ptw.WidgetProvider.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)) {
        Util.log("WidgetProvider.onReceive: Widget alarm");
        new UpdateWidgetThread(context).start();
        setAlarm(context);//from  w  w  w.ja  v  a2s.  c o m
    } else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED)) {
        Util.log("WidgetProvider.onReceive: Time change");
        setAlarm(context);
    } else if (intent.getAction().equals(PTW.INTENT_ACTION_SCHEDULE)) {
        Util.log("WidgetProvider.onReceive: Schedule Updated");

        final int[] appWidgetIds = getInstalledWidgets(context);
        if (appWidgetIds.length > 0) {
            /* Force full widget update */
            sRace = null;
            onUpdate(context, AppWidgetManager.getInstance(context), appWidgetIds);
        }
    } else if (intent.getAction().equals(PTW.INTENT_ACTION_ANSWERS)) {
        Util.log("WidgetProvider.onReceive: Answers submitted");
        final int[] appWidgetIds = getInstalledWidgets(context);
        if (appWidgetIds.length > 0) {
            new UpdateWidgetThread(context).start();
        }
    } else
        super.onReceive(context, intent);
}

From source file:com.eugene.fithealthmaingit.UI.UserInformationFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTIVITY_ONE_REQUEST && resultCode == getActivity().RESULT_OK) {
        if (data.hasExtra(ACTIVITY_ONE_RESULT)) {
            String result = data.getExtras().getString(ACTIVITY_ONE_RESULT);
            Toast.makeText(getActivity(), result, Toast.LENGTH_SHORT).show();
        }/*w  w  w. j  av a2s  . c o m*/
    }
}

From source file:com.tassadar.multirommgr.MainActivity.java

@Override
protected void onNewIntent(Intent i) {
    super.onNewIntent(i);
    if (i.hasExtra(INTENT_EXTRA_SHOW_ROM_LIST) && i.getBooleanExtra(INTENT_EXTRA_SHOW_ROM_LIST, false)) {
        selectItem(1);/*from   w  w  w.j  a  v  a  2  s.  co m*/
    }
}

From source file:com.ripperdesignandmultimedia.phoneblockplugin.PhoneBlockerPlugin.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * //from w  w w  . j a v a 2s.co m
 * @param ctx The context of the main Activity.
 */
public void setContext(CordovaInterface ctx) {
    super.setContext(ctx);
    this.phoneBlockerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
}

From source file:be.vbsteven.bmtodesk.BackgroundSharingService.java

@Override
/**/*from   w  w w .j  a va  2 s  .  co  m*/
 * starts the service and gets ready to send bookmark
 *
 * this service is supposed to only get started once for every bookmark
 * so if onStart is called it means a new bookmark needs to be sent
 */
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    // init notification manager
    nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (intent.hasExtra(Global.EXTRA_TITLE) && intent.hasExtra(Global.EXTRA_URL)) {
        title = intent.getStringExtra(Global.EXTRA_TITLE);
        url = intent.getStringExtra(Global.EXTRA_URL);
        Log.d(Global.TAG, "started BackgroundSharingService with values " + title + " " + url);

        sendToServer(title, url);
    } else {
        // if we're not called with a title and url, stop the service
        stopSelf();
        return;
    }
}

From source file:com.googlecode.setorientation.OrientationService.java

/**
 * Handles commands send to the service via {@link #onStart} and
 * {@link #onStartCommand}.// w w w .j  a  va 2 s  . c  om
 *
 * @param intent The command intent.
 */
private void handleCommand(Intent intent) {
    if (intent == null) {
        return;
    }

    if (intent.hasExtra(EXTRA_ORIENTATION)) {
        final int orientationCode = intent.getIntExtra(EXTRA_ORIENTATION, 0);
        final ScreenOrientation orientation = ScreenOrientation.fromCode(orientationCode);
        setOrientation(orientation);
    }
}

From source file:org.lol.reddit.activities.PostSubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit);

    typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type);
    usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username);
    subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit);
    titleEdit = (EditText) layout.findViewById(R.id.post_submit_title);
    textEdit = (EditText) layout.findViewById(R.id.post_submit_body);

    final Intent intent = getIntent();
    if (intent != null) {

        if (intent.hasExtra("subreddit")) {

            final String subreddit = intent.getStringExtra("subreddit");

            if (subreddit != null && subreddit.length() > 0 && !subreddit.matches("/?(r/)?all/?")
                    && subreddit.matches("/?(r/)?\\w+/?")) {
                subredditEdit.setText(subreddit);
            }//from w  ww .  j  ava2s  .  com

        } else if (Intent.ACTION_SEND.equalsIgnoreCase(intent.getAction())
                && intent.hasExtra(Intent.EXTRA_TEXT)) {
            final String url = intent.getStringExtra(Intent.EXTRA_TEXT);
            textEdit.setText(url);
        }

    } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) {
        titleEdit.setText(savedInstanceState.getString("post_title"));
        textEdit.setText(savedInstanceState.getString("post_body"));
        subredditEdit.setText(savedInstanceState.getString("subreddit"));
        typeSpinner.setSelection(savedInstanceState.getInt("post_type"));
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, R.string.error_toast_notloggedin);
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));
    typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes));

    // TODO remove the duplicate code here
    setHint();

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setHint();
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:org.quantumbadger.redreader.activities.PostSubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit);

    typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type);
    usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username);
    subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit);
    titleEdit = (EditText) layout.findViewById(R.id.post_submit_title);
    textEdit = (EditText) layout.findViewById(R.id.post_submit_body);

    final Intent intent = getIntent();
    if (intent != null) {

        if (intent.hasExtra("subreddit")) {

            final String subreddit = intent.getStringExtra("subreddit");

            if (subreddit != null && subreddit.length() > 0 && !subreddit.matches("/?(r/)?all/?")
                    && subreddit.matches("/?(r/)?\\w+/?")) {
                subredditEdit.setText(subreddit);
            }//from  w w  w. j  a v a2  s .c  o  m

        } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND)
                && intent.hasExtra(Intent.EXTRA_TEXT)) {
            final String url = intent.getStringExtra(Intent.EXTRA_TEXT);
            textEdit.setText(url);
        }

    } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) {
        titleEdit.setText(savedInstanceState.getString("post_title"));
        textEdit.setText(savedInstanceState.getString("post_body"));
        subredditEdit.setText(savedInstanceState.getString("subreddit"));
        typeSpinner.setSelection(savedInstanceState.getInt("post_type"));
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, R.string.error_toast_notloggedin);
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));
    typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes));

    // TODO remove the duplicate code here
    setHint();

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setHint();
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:com.germainz.identiconizer.services.IdenticonRemovalService.java

@Override
protected void onHandleIntent(Intent intent) {
    startForeground(SERVICE_NOTIFICATION_ID, createNotification());
    // If a predefined contacts list is provided, use it directly.
    // contactsList is set when this service is started from ContactsListActivity.
    if (intent.hasExtra("contactsList")) {
        ArrayList<ContactInfo> contactsList = intent.getParcelableArrayListExtra("contactsList");
        processPhotos(contactsList);//  w w w  .j av a  2s . com
    } else {
        processPhotos();
    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("CONTACTS_UPDATED"));
    stopForeground(true);
}