Example usage for android.content Intent getAction

List of usage examples for android.content Intent getAction

Introduction

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

Prototype

public @Nullable String getAction() 

Source Link

Document

Retrieve the general action to be performed, such as #ACTION_VIEW .

Usage

From source file:net.networksaremadeofstring.cyllell.Search.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_main);

    //Fancy title
    ((TextView) findViewById(R.id.TitleBarText))
            .setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/codeops_serif.ttf"));

    //List view to hold search results
    list = (ListView) findViewById(R.id.SearchResultsListView);

    //Prep the handler to do all the UI updating etc
    MakeHandler();//  w  w  w  .java2s. com

    //This is for the crafted search (not visible if the user came in via a search intent
    ((Button) findViewById(R.id.SearchButton)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            index = ((Spinner) findViewById(R.id.IndexChoice)).getSelectedItem().toString().toLowerCase();
            query = ((TextView) findViewById(R.id.SearchStringEditText)).getText().toString();
            PerformSearch(true);
        }
    });

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        findViewById(R.id.SearchParamContainer).setVisibility(8);
        //findViewById(R.id.ShowSearchParams).setVisibility(0);
        findViewById(R.id.SearchMainRelativeLayout).invalidate();

        query = intent.getStringExtra(SearchManager.QUERY);
        index = "node";

        PerformSearch(false);
    } else if (Intent.ACTION_SEARCH_LONG_PRESS.equals(intent.getAction())) {
        //findViewById(R.id.SearchParamContainer).setVisibility(0);
        //findViewById(R.id.ShowSearchParams).setVisibility(4);
    } else {
        //findViewById(R.id.SearchParamContainer).setVisibility(0);
        //findViewById(R.id.ShowSearchParams).setVisibility(4);
    }

    /*((ImageView)findViewById(R.id.ShowSearchParams)).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)
    {
       findViewById(R.id.SearchParamContainer).setVisibility(0);
      findViewById(R.id.ShowSearchParams).setVisibility(4);
      findViewById(R.id.SearchMainRelativeLayout).invalidate();
    }
     });
            
    ((ImageView)findViewById(R.id.HideSearchParams)).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)
    {
       findViewById(R.id.SearchParamContainer).setVisibility(8);
      findViewById(R.id.ShowSearchParams).setVisibility(0);
      findViewById(R.id.SearchMainRelativeLayout).invalidate();
              
    }
     });*/
}

From source file:ch.fixme.status.Widget.java

public void onReceive(Context ctxt, Intent intent) {
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        // Remove widget alarm
        int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        PendingIntent pi = PendingIntent.getService(ctxt, widgetId, getIntent(ctxt, widgetId), 0);
        AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
        am.cancel(pi);/*from w ww  .j  ava  2s.co m*/

        // remove preference
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
        Editor edit = prefs.edit();
        edit.remove(Main.PREF_API_URL_WIDGET + widgetId);
        edit.remove(Main.PREF_INIT_WIDGET + widgetId);
        edit.remove(Main.PREF_LAST_WIDGET + widgetId);
        edit.remove(Main.PREF_FORCE_WIDGET + widgetId);
        edit.commit();

        // Log.i(Main.TAG, "Remove widget alarm for id=" + widgetId);
    } else if (intent.hasExtra(WIDGET_IDS) && AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
        int[] ids = intent.getExtras().getIntArray(WIDGET_IDS);
        onUpdate(ctxt, AppWidgetManager.getInstance(ctxt), ids);
    } else
        super.onReceive(ctxt, intent);
}

From source file:com.bonsai.wallet32.PairWalletActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mRes = getApplicationContext().getResources();
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pair_wallet);

    // Set the state of the reduce false positives checkbox.
    boolean reduceFalsePositives = mPrefs.getBoolean("pref_reduceBloomFalsePositives", false);
    CheckBox chkbx = (CheckBox) findViewById(R.id.reduce_false_positives);
    chkbx.setChecked(reduceFalsePositives);
    chkbx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//from w  ww .  ja v  a 2 s . co  m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putBoolean("pref_reduceBloomFalsePositives", isChecked);
            editor.commit();
        }
    });

    // Hide the reduce bloom false positives if experimental off.
    Boolean isExperimental = mPrefs.getBoolean(SettingsActivity.KEY_EXPERIMENTAL, false);
    if (!isExperimental) {
        findViewById(R.id.reduce_false_positives).setVisibility(View.GONE);
        findViewById(R.id.reduce_space).setVisibility(View.GONE);
    }

    if (savedInstanceState == null) {
        final Intent intent = this.getIntent();
        final String action = intent.getAction();
        final String mimeType = intent.getType();

        if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && Nfc.MIMETYPE_WALLET32PAIRING.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(Nfc.MIMETYPE_WALLET32PAIRING, ndefMessage);
            JSONObject codeObj;

            try {
                String msg = new String(ndefMessagePayload, "UTF-8");
                codeObj = new JSONObject(msg);
            } catch (Exception ex) {
                String msg = "trouble deserializing pairing code: " + ex.toString() + " : "
                        + ndefMessagePayload.toString();
                mLogger.error(msg);
                Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
                return;
            }

            // Setup the wallet in a background task.
            new PairWalletTask().execute(codeObj);
        }
    }
}

From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java

/** Called when the activity is first created. */
@Override//w  w w . java 2  s . co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final ImageView imagePreview = (ImageView) findViewById(R.id.ImagePreview);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    Uri mImageUri = null;
    if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (mImageUri != null) {
                int origId = Integer.parseInt(mImageUri.getLastPathSegment());
                Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), origId,
                        MediaStore.Images.Thumbnails.MINI_KIND, (BitmapFactory.Options) null);
                imagePreview.setImageBitmap(bitmap);
            }
        }
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            tag_suggests);
    final MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.TagEditView);
    textView.setAdapter(adapter);
    textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    final Button button = (Button) findViewById(R.id.ZeitgeistSubmit);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            submitImage(textView.getText().toString());
        }
    });
}

From source file:com.ubikod.capptain.android.sdk.track.CapptainTrackReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    /* Once the application identifier is known */
    if ("com.ubikod.capptain.intent.action.APPID_GOT".equals(intent.getAction())) {
        /* Init the tracking agent */
        String appId = intent.getStringExtra("appId");
        CapptainTrackAgent.getInstance(context).onAppIdGot(appId);
    }//from   w ww .  j  a  v a2  s .com

    /* During installation, an install referrer may be triggered */
    else if ("com.android.vending.INSTALL_REFERRER".equals(intent.getAction())) {
        /* Forward this action to configured receivers */
        String forwardList = CapptainUtils.getMetaData(context)
                .getString("capptain:track:installReferrerForwardList");
        if (forwardList != null)
            for (String component : forwardList.split(","))
                if (!component.equals(getClass().getName())) {
                    Intent clonedIntent = new Intent(intent);
                    clonedIntent.setComponent(new ComponentName(context, component));
                    context.sendBroadcast(clonedIntent);
                }

        /* Guess store from referrer */
        String referrer = Uri.decode(intent.getStringExtra("referrer"));
        String store;

        /* GetJar uses an opaque string always starting with z= */
        if (referrer.startsWith("z="))
            store = "GetJar";

        /* Assume Android Market otherwise */
        else
            store = "Android Market";

        /* Look for a source parameter */
        Uri uri = Uri.parse("a://a?" + referrer);
        String source = uri.getQueryParameter("utm_source");

        /*
         * Skip "androidmarket" source, this is the default one when not set or installed via web
         * Android Market.
         */
        if ("androidmarket".equals(source))
            source = null;

        /* Send app info to register store/source */
        Bundle appInfo = new Bundle();
        appInfo.putString("store", store);
        if (source != null) {
            /* Parse source, if coming from capptain, it may be a JSON complex object */
            try {
                /* Convert JSON to bundle (just flat strings) */
                JSONObject jsonInfo = new JSONObject(source);
                Iterator<?> keyIt = jsonInfo.keys();
                while (keyIt.hasNext()) {
                    String key = keyIt.next().toString();
                    appInfo.putString(key, jsonInfo.getString(key));
                }
            } catch (JSONException jsone) {
                /* Not an object, process as a string */
                appInfo.putString("source", source);
            }
        }

        /* Send app info */
        CapptainAgent.getInstance(context).sendAppInfo(appInfo);
    }
}

From source file:com.magnet.mmx.client.TestMmxPush.java

@SmallTest
public void testPushMessageParsePush() throws JSONException {
    PushMessage pushMessage = PushMessage.decode(TEST_PUSH_STRING, null);
    assertTrue(pushMessage.getAction() == PushMessage.Action.PUSH);
    GCMPayload gcmPayload = (GCMPayload) pushMessage.getPayload();
    assertTrue(("mmx:p:" + Constants.PingPongCommand.notify.name())
            .equals(gcmPayload.getMmx().get(Constants.PAYLOAD_TYPE_KEY)));

    String idString = (String) gcmPayload.getMmx().get(Constants.PAYLOAD_ID_KEY);
    assertEquals(ID_VALUE, idString);//from ww w  .  j a  va  2s .  c  om

    String urlString = (String) gcmPayload.getMmx().get(Constants.PAYLOAD_CALLBACK_URL_KEY);
    assertEquals(CALLBACK_URL, urlString);
    assertEquals(CHIME_AIFF, gcmPayload.getSound());
    assertEquals(ORDER_STRING, gcmPayload.getBody());
    assertEquals(ORDER_STATUS, gcmPayload.getTitle());
    assertEquals(SIMPLE_ICON, gcmPayload.getIcon());

    Map<String, Object> customString = (Map<String, Object>) gcmPayload.getMmx()
            .get(Constants.PAYLOAD_CUSTOM_KEY);
    JSONObject jsonObject = new JSONObject(customString);
    assertEquals(DO_SOMETHING_IMMEDIATELY, jsonObject.getString("action"));
    assertEquals(IMAGE_URL, jsonObject.get("URL"));
    assertEquals(1, jsonObject.getInt("priority"));
    assertTrue(jsonObject.has("jsontext"));
    String jsonText = jsonObject.getString("jsontext");
    JSONObject json = new JSONObject(jsonText);
    assertEquals(RAHULS_MAC_BOOK_PRO_LOCAL, json.getString("from"));
    assertEquals(ID_VALUE, json.getString("id"));
    assertEquals(SELECTOR_FETCH_MESSAGE, json.getString("action"));

    // now format it as an Intent
    Intent pushIntent = MMXWakeupIntentService.buildPushIntent(gcmPayload);
    assertEquals(MMXClient.ACTION_PUSH_RECEIVED, pushIntent.getAction());
    assertEquals(ID_VALUE, pushIntent.getStringExtra(MMXClient.EXTRA_PUSH_ID));
    assertEquals(ORDER_STRING, pushIntent.getStringExtra(MMXClient.EXTRA_PUSH_BODY));
    assertEquals(ORDER_STATUS, pushIntent.getStringExtra(MMXClient.EXTRA_PUSH_TITLE));
    assertEquals(CHIME_AIFF, pushIntent.getStringExtra(MMXClient.EXTRA_PUSH_SOUND));
    assertEquals(SIMPLE_ICON, pushIntent.getStringExtra(MMXClient.EXTRA_PUSH_ICON));
    String jsonString = pushIntent.getStringExtra(MMXClient.EXTRA_PUSH_CUSTOM_JSON);
    JSONObject jsonObject2 = new JSONObject(jsonString);

    assertEquals(jsonObject.length(), jsonObject2.length());

}

From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivity.java

/**
 * Parse intent - ACTION_SEARCH or ACTION_VIEW
 * @param intent Intent object//w  ww  .  jav  a 2 s.  c  om
 */
protected void parseIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String searchQuery = intent.getStringExtra(SearchManager.QUERY);
        if (searchQuery != null)
            launchSearch(searchQuery, ticketManager.addIntent(intent));
    }
    if (Intent.ACTION_VIEW.equals(intent.getAction()) && (intent.getData() != null))
        viewUri(intent.getData(), ticketManager.addIntent(intent));

}

From source file:com.csipsimple.plugins.betamax.CallHandlerWeb.java

@Override
public void onReceive(Context context, Intent intent) {
    if (Utils.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {

        PendingIntent pendingIntent = null;
        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // We must handle that clean way cause when call just to
        // get the row in account list expect this to reply correctly
        if (!TextUtils.isEmpty(number) && !TextUtils.isEmpty(user) && !TextUtils.isEmpty(nbr)
                && !TextUtils.isEmpty(pwd) && !TextUtils.isEmpty(provider)) {
            // Build pending intent
            Intent i = new Intent(ACTION_DO_WEB_CALL);
            i.setClass(context, getClass());
            i.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
            pendingIntent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

        }/*  ww w .ja va 2  s  .co m*/

        // Build icon
        Bitmap bmp = Utils.getBitmapFromResource(context, R.drawable.icon_web);

        // Build the result for the row (label, icon, pending intent, and
        // excluded phone number)
        Bundle results = getResultExtras(true);
        if (pendingIntent != null) {
            results.putParcelable(Utils.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        }

        // Text for the row
        String providerName = "";
        Resources r = context.getResources();
        if (!TextUtils.isEmpty(provider)) {
            String[] arr = r.getStringArray(R.array.provider_values);
            String[] arrEntries = r.getStringArray(R.array.provider_entries);
            int i = 0;
            for (String prov : arr) {
                if (prov.equalsIgnoreCase(provider)) {
                    providerName = arrEntries[i];
                    break;
                }
                i++;
            }
        }
        results.putString(Intent.EXTRA_TITLE, providerName + " " + r.getString(R.string.web_callback));
        Log.d(THIS_FILE, "icon is " + bmp);
        if (bmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, bmp);
        }

        // DO *NOT* exclude from next tel: intent cause we use a http method
        // results.putString(Intent.EXTRA_PHONE_NUMBER, number);

    } else if (ACTION_DO_WEB_CALL.equals(intent.getAction())) {

        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // params
        List<NameValuePair> params = new LinkedList<NameValuePair>();
        params.add(new BasicNameValuePair("username", user));
        params.add(new BasicNameValuePair("password", pwd));
        params.add(new BasicNameValuePair("from", nbr));
        params.add(new BasicNameValuePair("to", number));
        String paramString = URLEncodedUtils.format(params, "utf-8");

        String requestURL = "https://www." + provider + "/myaccount/makecall.php?" + paramString;

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(requestURL);

        // Create a response handler
        HttpResponse httpResponse;
        try {
            httpResponse = httpClient.execute(httpGet);
            Log.d(THIS_FILE, "response code is " + httpResponse.getStatusLine().getStatusCode());
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                InputStreamReader isr = new InputStreamReader(httpResponse.getEntity().getContent());
                BufferedReader br = new BufferedReader(isr);

                String line;
                String fullReply = "";
                boolean foundSuccess = false;
                while ((line = br.readLine()) != null) {
                    if (!TextUtils.isEmpty(line) && line.toLowerCase().contains("success")) {
                        showToaster(context, "Success... wait a while you'll called back");
                        foundSuccess = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(line)) {
                        fullReply = fullReply.concat(line);
                    }
                }
                if (!foundSuccess) {
                    showToaster(context, "Error : server error : " + fullReply);
                }
            } else {
                showToaster(context, "Error : invalid request " + httpResponse.getStatusLine().getStatusCode());
            }
        } catch (ClientProtocolException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        } catch (IOException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        }

    }
}

From source file:jp.co.brilliantservice.android.writertduri.HomeActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String action = intent.getAction();
    if (TextUtils.isEmpty(action))
        return;/*from www .  ja va 2  s.co  m*/

    if (!action.equals(NfcAdapter.ACTION_TECH_DISCOVERED))
        return;

    // NdefMessage?
    String uri = "http://www.brilliantservice.co.jp/";
    NdefMessage message = createUriMessage(uri);

    // ??????????
    Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    List<String> techList = Arrays.asList(tag.getTechList());
    if (techList.contains(Ndef.class.getName())) {
        Ndef ndef = Ndef.get(tag);
        writeNdefToNdefTag(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEF tag", Toast.LENGTH_SHORT).show();
    } else if (techList.contains(NdefFormatable.class.getName())) {
        NdefFormatable ndef = NdefFormatable.get(tag);
        writeNdefToNdefFormatable(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEFFormatable tag", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(), "NDEF Not Supported", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.irccloud.android.RemoteInputService.java

@Override
protected void onHandleIntent(Intent intent) {
    boolean success = false;
    String sk = getSharedPreferences("prefs", 0).getString("session_key", "");
    if (intent != null && sk != null && sk.length() > 0) {
        final String action = intent.getAction();
        if (ACTION_REPLY.equals(action)) {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            if (remoteInput != null || intent.hasExtra("reply")) {
                Crashlytics.log(Log.INFO, "IRCCloud", "Got reply from RemoteInput");
                String reply = remoteInput != null ? remoteInput.getCharSequence("extra_reply").toString()
                        : intent.getStringExtra("reply");
                if (reply.length() > 0 && !reply.contains("\n/")
                        && (!reply.startsWith("/") || reply.toLowerCase().startsWith("/me ")
                                || reply.toLowerCase().startsWith("/slap "))) {
                    try {
                        JSONObject o = NetworkConnection.getInstance().say(intent.getIntExtra("cid", -1),
                                intent.getStringExtra("to"), reply, sk);
                        success = o.getBoolean("success");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }/*  w  ww .  j  a v a 2 s . c om*/
                }
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel(intent.getIntExtra("bid", 0));
                if (intent.hasExtra("eids")) {
                    int bid = intent.getIntExtra("bid", -1);
                    long[] eids = intent.getLongArrayExtra("eids");
                    for (int j = 0; j < eids.length; j++) {
                        if (eids[j] > 0) {
                            Notifications.getInstance().dismiss(bid, eids[j]);
                        }
                    }
                }
                if (!success)
                    Notifications.getInstance().alert(intent.getIntExtra("bid", -1), "Sending Failed",
                            reply.startsWith("/") ? "Please launch the IRCCloud app to send this command"
                                    : "Your message was not sent. Please try again shortly.");
            } else {
                Crashlytics.log(Log.ERROR, "IRCCloud", "RemoteInputService received no remoteinput");
            }
        }
    }
}