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:mai.whack.StickyNotesActivity.java

private void onDataRead(Intent intent) {
    // Parse the intent
    NdefMessage[] msgs = null;// w  ww  .  j ava  2 s .  c  o m
    String action = intent.getAction();
    byte[] tagId = null;
    if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
            }
        } else {
            // Unknown tag type
            byte[] empty = new byte[] {};
            NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
            NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
            msgs = new NdefMessage[] { msg };
        }
    } else {
        Log.d(TAG, "Unknown intent.");
        finish();
    }

    String msg = new String(msgs[0].getRecords()[0].getPayload());
    mHttpGetThread = new HttpGetThread("http://192.168.1.192/store/" + toHex(tagId));
    mHttpGetThread.start();
    // mHttpPostThread = new HttpPostThread("aaaaa", "bbbbb", "sdgsdfdsfs");
    // mHttpPostThread.start();
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        //use the query to search your data somehow
    }//w  w w  . jav a  2  s . co  m
}

From source file:ack.me.truconnectandroiddemo.MainActivity.java

private void initBroadcastReceiver() {
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override//from   www .  j  a v  a 2 s.co  m
        public void onReceive(Context context, Intent intent) {
            // Get extra data included in the Intent
            String action = intent.getAction();

            switch (action) {
            case TruconnectService.ACTION_SCAN_RESULT:
                addDeviceToList(TruconnectService.getData(intent));
                break;

            case TruconnectService.ACTION_CONNECTED:
                String deviceName = TruconnectService.getData(intent);

                mConnected = true;
                dismissConnectDialog();
                showToast("Connected to " + deviceName, Toast.LENGTH_SHORT);
                Log.d(TAG, "Connected to " + deviceName);

                mTruconnectManager.setMode(TruconnectManager.MODE_COMMAND_REMOTE);
                mTruconnectManager.setSystemCommandMode(TruconnectCommandMode.MACHINE);
                startDeviceInfoActivity();
                break;

            case TruconnectService.ACTION_DISCONNECTED:
                break;

            case TruconnectService.ACTION_MODE_WRITE:
                break;

            case TruconnectService.ACTION_MODE_READ:
                break;

            case TruconnectService.ACTION_DATA_WRITE:
                break;

            case TruconnectService.ACTION_DATA_READ:
                break;

            case TruconnectService.ACTION_COMMAND_SENT:
                String command = TruconnectService.getCommand(intent).toString();
                Log.d(TAG, "Command " + command + " sent");
                break;

            case TruconnectService.ACTION_COMMAND_RESULT:
                break;

            case TruconnectService.ACTION_ERROR:
                TruconnectErrorCode errorCode = TruconnectService.getErrorCode(intent);
                //handle errors
                break;
            }
        }
    };
}

From source file:com.nfc.gemkey.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    if (DEBUG)//from w w w . ja  va  2s. c  o m
        Log.d(TAG, "onNewIntent");

    final String action = intent.getAction();
    if (action.equals(NfcAdapter.ACTION_TAG_DISCOVERED)) {
        if (DEBUG)
            Log.i(TAG, "Discovered tag with intent: " + action);
        Tag myTag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        String nfc_tag_id = bytesToHexString(myTag.getId()).toUpperCase();
        tagId.setText("Tag ID : " + nfc_tag_id);

        if (mCheckTagInfoThread != null && mCheckTagInfoThread.isAlive()) {
            mCheckTagInfoThread.terminate();
            mCheckTagInfoThread = null;
        }
        mCheckTagInfoThread = new CheckTagInfoThread(nfc_tag_id);
        mCheckTagInfoThread.start();
    }
}

From source file:com.facebook.internal.LikeActionController.java

private static void registerSessionBroadcastReceivers() {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(applicationContext);

    IntentFilter filter = new IntentFilter();
    filter.addAction(Session.ACTION_ACTIVE_SESSION_UNSET);
    filter.addAction(Session.ACTION_ACTIVE_SESSION_CLOSED);
    filter.addAction(Session.ACTION_ACTIVE_SESSION_OPENED);

    broadcastManager.registerReceiver(new BroadcastReceiver() {
        @Override//w ww.  j a va  2 s  .  c om
        public void onReceive(Context receiverContext, Intent intent) {
            if (isPendingBroadcastReset) {
                return;
            }

            String action = intent.getAction();
            final boolean shouldClearDisk = Utility.areObjectsEqual(Session.ACTION_ACTIVE_SESSION_UNSET, action)
                    || Utility.areObjectsEqual(Session.ACTION_ACTIVE_SESSION_CLOSED, action);

            isPendingBroadcastReset = true;
            // Delaying sending the broadcast to reset, because we might get many successive calls from Session
            // (to UNSET, SET & OPEN) and a delay would prevent excessive chatter.
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    // Bump up the objectSuffix so that we don't have a filename collision between a cache-clear and
                    // and a cache-read/write.
                    //
                    // NOTE: We know that onReceive() was called on the main thread. This means that even this code
                    // is running on the main thread, and therefore, there aren't synchronization issues with
                    // incrementing the objectSuffix and clearing the caches here.
                    if (shouldClearDisk) {
                        objectSuffix = (objectSuffix + 1) % MAX_OBJECT_SUFFIX;
                        applicationContext
                                .getSharedPreferences(LIKE_ACTION_CONTROLLER_STORE, Context.MODE_PRIVATE).edit()
                                .putInt(LIKE_ACTION_CONTROLLER_STORE_OBJECT_SUFFIX_KEY, objectSuffix).apply();

                        // Only clearing the actual caches. The MRU index will self-clean with usage.
                        // Clearing the caches is necessary to prevent leaking like-state across sessions.
                        cache.clear();
                        controllerDiskCache.clearCache();
                    }

                    broadcastAction(null, ACTION_LIKE_ACTION_CONTROLLER_DID_RESET);
                    isPendingBroadcastReset = false;
                }
            }, 100);
        }
    }, filter);
}

From source file:me.calebjones.blogsite.network.PostDownloader.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d("The Jones Theory", "PostDownloader onHandleIntent + " + intent.getAction() + " "
            + SharedPrefs.getInstance().isDownloading());
    if (!SharedPrefs.getInstance().isDownloading()) {
        SharedPrefs.getInstance().setLastRedownladTime(System.currentTimeMillis());
        switch (intent.getAction()) {
        case DOWNLOAD_ALL:
            Log.d("The Jones Theory",
                    "DOWNLOAD ALL - Downloading = " + SharedPrefs.getInstance().isDownloading());
            notificationService();//  ww  w . ja va 2 s.c  om
            getPostAll();
            break;
        case DOWNLOAD_MISSING:
            Log.d("The Jones Theory",
                    "DOWNLOAD MISSING - Downloading = " + SharedPrefs.getInstance().isDownloading());
            notificationService();
            getPostMissing();
            break;
        }
    }
}

From source file:org.umit.icm.mobile.gui.ControlActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.controlactivity);
    WebsiteSuggestButton = (Button) this.findViewById(R.id.suggestWebsite);
    ServiceSuggestButton = (Button) this.findViewById(R.id.suggestService);
    scanButton = (Button) this.findViewById(R.id.scanButton);
    //        filterButton = (Button) this.findViewById(R.id.filterButton);
    //       servicesFilterButton = (Button) this.findViewById(R.id.serviceFilterButton);
    mapSelectionButton = (Button) this.findViewById(R.id.mapSelectionButton);
    enableTwitterButton = (Button) this.findViewById(R.id.enableTwitterButton);
    bugReportButton = (Button) this.findViewById(R.id.bugReportButton);
    aboutButton = (Button) this.findViewById(R.id.aboutButton);
    scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off));
    try {/*from www .  j  a  va  2 s  . co  m*/
        if (Globals.runtimeParameters.getTwitter().equals("Off")) {
            enableTwitterButton.setText(getString(R.string.enable_twitter_button));
        } else {
            enableTwitterButton.setText(getString(R.string.disable_twitter_button));
        }
    } catch (RuntimeException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("org.umit.icm.mobile.CONTROL_ACTIVITY")) {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on));
            }
        }
    };

    registerReceiver(receiver, new IntentFilter("org.umit.icm.mobile.CONTROL_ACTIVITY"));

    WebsiteSuggestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            WebsiteSuggestionDialog websiteSuggestionDialog = new WebsiteSuggestionDialog(ControlActivity.this,
                    "", new OnReadyListener());
            websiteSuggestionDialog.show();
        }

    });

    ServiceSuggestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ServiceSuggestionDialog suggestionDialog = new ServiceSuggestionDialog(ControlActivity.this, "",
                    new OnReadyListener());
            suggestionDialog.show();
        }

    });

    enableTwitterButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                if (Globals.runtimeParameters.getTwitter().equals("Off")) {
                    progressDialog = ProgressDialog.show(ControlActivity.this, getString(R.string.loading),
                            getString(R.string.retrieving_website), true, false);
                    new LaunchBrowser().execute();
                    TwitterDialog twitterDialog = new TwitterDialog(ControlActivity.this, "");
                    twitterDialog.show();
                    enableTwitterButton.setText(getString(R.string.disable_twitter_button));
                } else {
                    Globals.runtimeParameters.setTwitter("Off");
                    enableTwitterButton.setText(getString(R.string.enable_twitter_button));
                }
            } catch (RuntimeException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    });

    mapSelectionButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            MapSelectionDialog MapSelectionDialog = new MapSelectionDialog(ControlActivity.this, "");
            MapSelectionDialog.show();
        }

    });

    /*      filterButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) {                                           
        Intent intent = new Intent(ControlActivity.this, WebsiteFilterActivity.class);                
       startActivity(intent); 
     }
            
           }  );
                  
          servicesFilterButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) {                                           
        Intent intent = new Intent(ControlActivity.this, ServiceFilterActivity.class);                
       startActivity(intent); 
     }
            
           }  );*/

    bugReportButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(ControlActivity.this, BugReportActivity.class);
            startActivity(intent);
        }

    });

    aboutButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            String msg = getString(R.string.about_text) + "\n" + getString(R.string.link_to_open_monitor) + "\n"
                    + getString(R.string.link_to_umit) + "\n" + getString(R.string.icons_by);

            final SpannableString spannableString = new SpannableString(msg);
            Linkify.addLinks(spannableString, Linkify.ALL);

            AlertDialog alertDialog = new AlertDialog.Builder(ControlActivity.this).create();
            alertDialog.setTitle(getString(R.string.about_button));
            alertDialog.setMessage(spannableString);
            alertDialog.setIcon(R.drawable.umit_128);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();

                }
            });
            alertDialog.show();

        }

    });

    scanButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (Globals.scanStatus.equalsIgnoreCase(getString(R.string.scan_on))) {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on));
                Globals.scanStatus = getString(R.string.scan_off);
                stopService(new Intent(ControlActivity.this, ConnectivityService.class));
            }

            else {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off));
                Globals.scanStatus = getString(R.string.scan_on);
                startService(new Intent(ControlActivity.this, ConnectivityService.class));
            }

            try {
                Globals.runtimeParameters.setScanStatus(Globals.scanStatus);
            } catch (RuntimeException e) {
                e.printStackTrace();
            }

            Context context = getApplicationContext();
            CharSequence text = getString(R.string.toast_scan_change) + " " + Globals.scanStatus;
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }

    });

}

From source file:com.mobicage.rogerthat.plugins.scan.ProcessScanActivity.java

private SafeBroadcastReceiver getBroadcastReceiver() {
    return new SafeBroadcastReceiver() {
        @Override/*from  www  .j a va 2s.  c o m*/
        public String[] onSafeReceive(Context context, Intent intent) {
            T.UI();
            if (intent.getAction().equals(FriendsPlugin.FRIEND_INFO_RECEIVED_INTENT)) {
                final String emailHash = intent.getStringExtra(EMAILHASH);
                if (emailHash != null && emailHash.equals(mExpectedEmailHash)) {
                    abortProcessing();

                    if (intent.getBooleanExtra(ProcessScanActivity.SUCCESS, true)) {
                        final Intent inviteFriendIntent = new Intent(ProcessScanActivity.this,
                                InviteFriendActivity.class);
                        // Copy extra from other intent
                        for (String extra : new String[] { AVATAR, DESCRIPTION, DESCRIPTION_BRANDING, EMAIL,
                                EMAILHASH, NAME, QUALIFIED_IDENTIFIER }) {
                            inviteFriendIntent.putExtra(extra, intent.getStringExtra(extra));
                        }
                        inviteFriendIntent.putExtra(TYPE,
                                intent.getLongExtra(TYPE, FriendsPlugin.FRIEND_TYPE_USER));
                        startActivity(inviteFriendIntent);
                        finish();
                        return new String[] { intent.getAction() };
                    } else {
                        showError(intent);
                    }

                } else {
                    // ignore
                }
            } else if (intent.getAction().equals(FriendsPlugin.SERVICE_ACTION_INFO_RECEIVED_INTENT)) {
                if (mExpectedEmailHash != null && mExpectedEmailHash.equals(intent.getStringExtra(EMAILHASH))
                        && mExpectedAction != null
                        && mExpectedAction.equals(intent.getStringExtra(POKE_ACTION))) {
                    abortProcessing();

                    if (intent.getBooleanExtra(SUCCESS, true)) {
                        final Intent serviceActionIntent = new Intent(ProcessScanActivity.this,
                                ServiceActionActivity.class);
                        // Copy extra from other intent
                        for (String extra : new String[] { AVATAR, DESCRIPTION, DESCRIPTION_BRANDING, EMAIL,
                                NAME, POKE_DESCRIPTION, QUALIFIED_IDENTIFIER, STATIC_FLOW, STATIC_FLOW_HASH }) {
                            serviceActionIntent.putExtra(extra, intent.getStringExtra(extra));
                        }
                        serviceActionIntent.putExtra(EMAILHASH, mExpectedEmailHash);
                        serviceActionIntent.putExtra(POKE_ACTION, mExpectedAction);
                        serviceActionIntent.setAction(FriendsPlugin.SERVICE_ACTION_INFO_RECEIVED_INTENT);
                        serviceActionIntent.putExtra(SUCCESS, true);
                        startActivity(serviceActionIntent);
                        finish();
                        // TODO: set success?

                        return new String[] { intent.getAction() };
                    } else {
                        showError(intent);
                    }
                } else {
                    // ignore
                }
            } else if (intent.getAction().equals(URL_REDIRECTION_DONE)) {
                final String emailHash = intent.getStringExtra(EMAILHASH);
                if (intent.hasExtra(POKE_ACTION)) {
                    final String pokeAction = intent.getStringExtra(POKE_ACTION);
                    getServiceActionInfo(emailHash, pokeAction);
                } else {
                    processEmailHash(emailHash);
                }
                return new String[] { intent.getAction() };
            }

            return null; // Intent was ignored
        }

    };
}

From source file:com.ekumen.tangobot.application.MainActivity.java

private void onUsbDeviceAttached(Intent intent) {
    if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
        UsbDevice usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        onDeviceReady(usbDevice);//from w ww  .  j a  v a  2  s.  com
    }
}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

@SuppressLint("NewApi")
@Override//from  w  w  w. j a va  2  s.co  m
public void onReceive(Context context, Intent intent) {
    long ts = System.currentTimeMillis();
    if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
        context.unregisterReceiver(this);
        try {
            JSONArray neighs = new JSONArray();
            WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            for (ScanResult r : wm.getScanResults()) {
                JSONObject o = new JSONObject();
                o.put("frequency", r.frequency);
                o.put("level", r.level);
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    o.put("timestamp", r.timestamp);
                }
                o.put("bssid", r.BSSID);
                o.put("ssid", r.SSID);
                neighs.put(o);
            }

            JSONObject wifi = new JSONObject();
            wifi.put("list", neighs);
            Helpers.sendResultObj(context, "wifi_neigh", ts, wifi);

        } catch (JSONException jex) {
            Log.w(Constants.LOGTAG, "failed to create json object", jex);
        }
        // this will clean the CPU lock too if running on the bg
        Helpers.releaseWifiLock();
    }
}