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:org.androidpn.client.NotificationReceiver.java

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

    context = contextParam;/*from www.  ja v a 2s . co  m*/
    Log.d(LOGTAG, "NotificationReceiver.onReceive()...");
    String action = intent.getAction();
    Log.d(LOGTAG, "action=" + action);

    if (Constants.ACTION_SHOW_NOTIFICATION.equals(action)) {
        String notificationId = intent.getStringExtra(Constants.NOTIFICATION_ID);
        String notificationApiKey = intent.getStringExtra(Constants.NOTIFICATION_API_KEY);
        String notificationTitle = intent.getStringExtra(Constants.NOTIFICATION_TITLE);
        final String notificationMessage = intent.getStringExtra(Constants.NOTIFICATION_MESSAGE);
        String notificationUri = intent.getStringExtra(Constants.NOTIFICATION_URI);

        Log.d(LOGTAG, "notificationMessage=" + notificationMessage);

        Notifier notifier = new Notifier(contextParam);
        notifier.notify(notificationId, notificationApiKey, notificationTitle, notificationMessage,
                notificationUri);
        // ?notificationTitle??
        try {
            Integer.parseInt(notificationTitle);

        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("notificationTitle??");
        }
        switch (Integer.parseInt(notificationTitle)) {
        case ConfigTest.LOGIC_ORDER:
            Editor editor = context.getSharedPreferences(ConfigSP.SP_reseach, Context.MODE_PRIVATE).edit();// ?
            editor.putString(ConfigSP.SP_ISUpload, "false").commit();

            if (ConfigTest.isDo == 0) {// ?
                new Thread() {
                    public void run() {
                        String registerIp = context
                                .getSharedPreferences(ConfigSP.SP_reseach, Context.MODE_PRIVATE)
                                .getString(ConfigSP.SP_reseach_ip, "");
                        String serverIp = "http://" + registerIp;
                        strImsi = context.getSharedPreferences(ConfigSP.SP_reseach, Context.MODE_PRIVATE)
                                .getString(ConfigSP.SP_reseach_Imsi, "");
                        NameValuePair pairImsi = new BasicNameValuePair("imsino", strImsi); // Imsi
                        List<NameValuePair> paramList = new ArrayList<NameValuePair>();
                        paramList.add(pairImsi);
                        String url = serverIp + ":8080/ResearchProject/sendcasemanager/sendstate";
                        NetUtil.getInstance().httpUpload(context, url, paramList);
                        // ?
                        ConfigTest.isDo = 1;
                        logic(notificationMessage);
                    };
                }.start();
            } else {
                Log.e("", "");
            }

            break;
        case ConfigTest.SIGNAL_ORDER:
            switchSignaleSrvice(notificationMessage);
            break;
        case ConfigTest.POWERLOW_SET:
            setpowerlow(notificationMessage);
            break;
        case ConfigTest.LOG_ORDER:
            /**
             * ?????
             */
            /*
             * new Thread() { public void run() { try {
             * LogUpLoad.newUpLoad(context); } catch (Exception e) { // TODO
             * Auto-generated catch block e.printStackTrace(); } };
             * }.start();
             */
            break;
        case ConfigTest.ADB_ORDER:
            onAdb(notificationMessage);
            break;
        default:
            System.out.println("?");
            break;
        }
    }

}

From source file:edu.stanford.mobisocial.dungbeetle.NearbyActivity.java

private void findBluetooth() {
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        Intent bt = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(bt, RESULT_BT_ENABLE);
        return;/*from  w  w  w  .  ja v  a2s.  c  om*/
    }

    // Create a BroadcastReceiver for ACTION_FOUND
    final IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

    final BroadcastReceiver receiver = new BroadcastReceiver() {
        public void onReceive(final Context context, final Intent intent) {
            String action = intent.getAction();
            // When discovery finds a device
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                new Thread() {
                    public void run() {
                        BluetoothBeacon.OnDiscovered discovered = new BluetoothBeacon.OnDiscovered() {
                            @Override
                            public void onDiscovered(final byte[] data) {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            JSONObject obj = new JSONObject(new String(data));
                                            mNearbyList.add(
                                                    new NearbyItem(NearbyItem.Type.FEED, obj.getString("name"),
                                                            Uri.parse(obj.getString("dynuri")), null));
                                            mAdapter.notifyDataSetChanged();
                                        } catch (JSONException e) {
                                            Log.e(TAG, "Error getting group info over bluetooth", e);
                                        }
                                    }
                                });
                            }
                        };
                        // Get the BluetoothDevice object from the Intent
                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                        BluetoothBeacon.discover(NearbyActivity.this, device, discovered);
                    };
                }.start();
            }
            if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                unregisterReceiver(this);
            }
        }
    };

    registerReceiver(receiver, filter); // Don't forget to unregister during
                                        // onDestroy
    BluetoothAdapter.getDefaultAdapter().startDiscovery();
    Toast.makeText(this, "Scanning Bluetooth...", 500).show();
}

From source file:edu.cens.loci.ui.PlaceListActivity.java

/**
 * USE CASES:/* ww w. j a v  a 2  s  .  com*/
 * 
 * 1. DEFAULT :
 *       list places and when selected, ACTION_VIEW
 * 
 *       ACTION ... send ACTION_VIEW content://places/pid 
 *       SHOW ...
 *    - Suggested places ... add "View GPS Places"
 *    - Registered places ...
 *    - Blocked places ...
 *    - Filter by tag ...
 * 
 * 2. INSERT_OR_EDIT :
 *    list "create a new place" and "registered" places, when selected, ACTION_EDIT
 *    
 *    ACTION ... send ACTION_EDIT content://places/pid or ACTION_INSERT content://places
 *    - show all suggested/registered/blocked places
 *    SHOW...
 *    - "create a new place" and "registered places"
 *    
 * 3. PICK :
 *       list places and when selected, return with a uri.
 * 
 *       ACTION ... return a data URL back to the caller
 *       SHOW... 
 * 
 * 4. SEARCH :
 *     TBD
 * 
 */

@Override
protected void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    setContentView(R.layout.place_list);

    // Resolve the intent
    final Intent intent = getIntent();

    String title = intent.getStringExtra(UI.TITLE_EXTRA_KEY);
    if (title != null) {
        setTitle(title);
    }

    String action = intent.getAction();

    if (Intent.ACTION_VIEW.equals(action)) {
        mMode = MODE_VIEW;
    } else if (Intents.UI.ACTION_INSERT.equals(action)) {
        mMode = MODE_INSERT;
    } else if (Intents.UI.ACTION_CREATE_OR_ADDTO_FROM_SUGGESTED_PLACE.equals(action)) {
        mMode = MODE_REGISTER_SUGGESTED;
    } else if (Intent.ACTION_PICK.equals(action)) {
        mMode = MODE_PICK;
    }

    MyLog.i(LociConfig.D.UI.DEBUG, TAG, String.format("List: mode=%d (%s)", mMode, action));

    Bundle extras = intent.getExtras();

    if (extras != null) {
        if (extras.containsKey(Intents.UI.FILTER_STATE_EXTRA_KEY))
            mFilterState = extras.getInt(Intents.UI.FILTER_STATE_EXTRA_KEY);
        if (extras.containsKey(Intents.UI.FILTER_TYPE_EXTRA_KEY))
            mFilterType = extras.getInt(Intents.UI.FILTER_TYPE_EXTRA_KEY);
        if (extras.containsKey(Intents.UI.FILTER_TAG_EXTRA_KEY))
            mFilterTag = extras.getString(Intents.UI.FILTER_TAG_EXTRA_KEY);
        if (extras.containsKey(Intents.UI.LIST_ORDER_EXTRA_KEY))
            mListOrder = extras.getInt(Intents.UI.LIST_ORDER_EXTRA_KEY);
    }

    mDbUtils = new LociDbUtils(this);
}

From source file:com.gimranov.zandy.app.ItemActivity.java

private Cursor prepareCursor() {
    Cursor cursor;//from w  w  w.  j  a v a2s. com
    // Be ready for a search
    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        query = intent.getStringExtra(SearchManager.QUERY);
        cursor = getCursor(query);
        this.setTitle(getResources().getString(R.string.search_results, query));
    } else if (query != null) {
        cursor = getCursor(query);
        this.setTitle(getResources().getString(R.string.search_results, query));
    } else if (intent.getStringExtra("com.gimranov.zandy.app.tag") != null) {
        String tag = intent.getStringExtra("com.gimranov.zandy.app.tag");
        Query q = new Query();
        q.set("tag", tag);
        cursor = getCursor(q);
        this.setTitle(getResources().getString(R.string.tag_viewing_items, tag));
    } else {
        collectionKey = intent.getStringExtra("com.gimranov.zandy.app.collectionKey");

        ItemCollection coll;

        if (collectionKey != null && (coll = ItemCollection.load(collectionKey, db)) != null) {
            cursor = getCursor(coll);
            this.setTitle(coll.getTitle());
        } else {
            cursor = getCursor();
            this.setTitle(getResources().getString(R.string.all_items));
        }
    }
    return cursor;
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

/**
 * Handle message intent filter for attachments
 * //from   w ww . jav  a 2 s .c  om
 * @param intent
 */
private void handleIntentFilter(Intent intent) {
    attachments_type.put(ATTACHMENT_TYPE.IMAGE, "image/*");
    attachments_type.put(ATTACHMENT_TYPE.TEXT_FILE, "application/*");

    String action = intent.getAction();
    String type = intent.getType();

    // Single attachment
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        Uri fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        file_uris.add(fileUri);
        handleReceivedFile();
    }

    // Multiple Attachments
    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        ArrayList<Uri> fileUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        file_uris.addAll(fileUris);
        handleReceivedFile();

    }

    // note.note send as mail
    if (intent.hasExtra("note_body")) {
        EditText edtBody = (EditText) findViewById(R.id.edtMessageBody);
        String body = intent.getExtras().getString("note_body");
        edtBody.setText(HTMLHelper.stringToHtml(body));
        is_note_body = true;
    }

}

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

public void initDownloadComponents() {

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override/*from ww  w .jav a 2  s.  c  o m*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                //
            }
        }
    };

    context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    context.unregisterReceiver(receiver);
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    mComtext = context;/*from   www . ja  v  a 2 s  . com*/
    String action = intent.getAction();
    Log.i("sai", "onReceive: " + action);

    super.onReceive(context, intent);

    if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action)
            || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action)
            || Intent.ACTION_LOCALE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId);
                // SPRD for bug421127 add am/pm for widget
                WidgetUtils.setTimeFormat(widget,
                        (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
                        R.id.the_clock);
                WidgetUtils.setClockSize(context, widget, ratio);
                //refreshAlarm(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
        if (!ACTION_ON_QUARTER_HOUR.equals(action)) {
            cancelAlarmOnQuarterHour(context);
        }
        startAlarmOnQuarterHour(context);
    }
    // cg sai.pan begin
    else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshBtStatus(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        Log.e("sai", "wifiStatus" + wifiStatus);
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                if (WifiManager.WIFI_STATE_ENABLED == wifiStatus
                        || WifiManager.WIFI_STATE_ENABLING == wifiStatus) {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on);
                } else {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off);
                }
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshWifiStatus(context, widget);
            }
        }
    } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
        if (isNetworkConnected(context)) {
            Log.e("sai", "isNetworkConnected true");
            requestLocation(context);
        } else {
            Log.e("sai", "isNetworkConnected false");
        }
    }
}

From source file:com.concentricsky.android.khanacademy.data.KADataService.java

/**
 * Used for long-running operations including library updates and video downloads.
 * //from   w w  w .  j ava 2 s. c  om
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("KADataService", "Received start id " + startId + ": " + intent);

    PendingIntent pendingIntent = null;
    if (intent.hasExtra(Intent.EXTRA_INTENT)) {
        // TODO : use this intent. It needs to be called with the results of requestLibraryUpdate (so far)
        pendingIntent = intent.getParcelableExtra(Intent.EXTRA_INTENT);
    }

    if (ACTION_LIBRARY_UPDATE.equals(intent.getAction())) {
        requestLibraryUpdate(startId, pendingIntent, intent.getBooleanExtra(EXTRA_FORCE, false));
        return START_REDELIVER_INTENT;
    }

    if (ACTION_UPDATE_DOWNLOAD_STATUS.equals(intent.getAction())) {
        Log.d(LOG_TAG, "update download status");
        updateDownloadStatus(intent, pendingIntent, startId);
        return START_REDELIVER_INTENT;
    }

    /*
    START_NOT_STICKY
    Do not recreate the service, unless there are pending intents to deliver. This is the 
    safest option to avoid running your service when not necessary and when your application 
    can simply restart any unfinished jobs.
    START_STICKY
    Recreate the service and call onStartCommand(), but do not redeliver the last intent. 
    Instead, the system calls onStartCommand() with a null intent, unless there were pending 
    intents to start the service, in which case, those intents are delivered. This is suitable 
    for media players (or similar services) that are not executing commands, but running 
    indefinitely and waiting for a job.
    START_REDELIVER_INTENT
    Recreate the service and call onStartCommand() with the last intent that was delivered 
    to the service. Any pending intents are delivered in turn. This is suitable for services 
    that are actively performing a job that should be immediately resumed, such as downloading a file.
     */

    // If we reach this point, the intent has some unknown action, so just ignore it and stop.
    this.stopSelfResult(startId);
    return START_NOT_STICKY;
}

From source file:com.hybris.mobile.activity.OrderDetailActivity.java

private void handleIntent(Intent intent) {

    if (Hybris.isUserLoggedIn()) {
        if (intent.hasExtra("orderDetails")) {
            ((TextView) findViewById(R.id.lbl_thankYou)).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.lbl_orderConfirmation)).setVisibility(View.VISIBLE);
            // TODO
            setmOrderDetails(JsonUtils.fromJson(intent.getStringExtra("orderDetails"), CartOrder.class));
        }/* w  ww  .  j a va2s  . c o  m*/
        if (intent.hasExtra(DataConstants.ORDER_ID)) {
            setmOrderID(intent.getStringExtra(DataConstants.ORDER_ID));
        }
        // Call from another application (QR Code) 
        else if (StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) {
            setmOrderID(RegexUtil.getOrderIdFromHybrisPattern(intent.getDataString()));
        }
    }
    // User not logged in, redirection to the login page
    else {
        Intent loginIntent = new Intent(this, LoginActivity.class);

        // Call from another application (QR Code) 
        if (StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) {
            loginIntent.putExtra(DataConstants.ORDER_ID,
                    RegexUtil.getOrderIdFromHybrisPattern(intent.getDataString()));
        }

        loginIntent.putExtra(DataConstants.INTENT_DESTINATION, DataConstants.INTENT_ORDER_DETAILS);
        loginIntent.putExtras(intent);
        startActivity(loginIntent);
    }
}

From source file:com.orange.oidc.secproxy_service.Service.java

@Override
public IBinder onBind(Intent intent) {
    // Select the interface to return.  If your service only implements
    // a single interface, you can just return it here without checking
    // the Intent.
    if (IRemoteService.class.getName().equals(intent.getAction())) {
        showProtectedNotifIcon();//  w  w  w.  java2  s . c om
        Logd(TAG, "onBind Service");
        return mBinder;
    }
    if (IRemoteServiceInternal.class.getName().equals(intent.getAction())) {
        Logd(TAG, "onBind ServiceInternal");
        return mBinderInternal;
    }
    return null;
}