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:com.slim.turboeditor.activity.MainActivity.java

/**
 * Parses the intent/*from   ww  w.j  a  v a  2  s  . c o  m*/
 */
private void parseIntent(Intent intent) {
    final String action = intent.getAction();
    final String type = intent.getType();

    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)
            || Intent.ACTION_PICK.equals(action) && type != null) {
        Uri uri = intent.getData();
        File newFile = new File(uri.getPath());
        newFileToOpen(newFile, "");
    } else if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            newFileToOpen(null, intent.getStringExtra(Intent.EXTRA_TEXT));
        }
    }
}

From source file:io.teak.sdk.Teak.java

@Override
public void onReceive(Context inContext, Intent intent) {
    final Context context = inContext.getApplicationContext();

    if (!Teak.isEnabled()) {
        Log.e(LOG_TAG, "Teak is disabled, ignoring onReceive().");
        return;/*w  w  w . j a v  a2  s.c  o  m*/
    }

    String action = intent.getAction();

    if (GCM_RECEIVE_INTENT_ACTION.equals(action)) {
        final TeakNotification notif = TeakNotification.remoteNotificationFromIntent(context, intent);
        if (notif == null) {
            return;
        }

        // Send Notification Received Metric
        Session.whenUserIdIsReadyRun(new Session.SessionRunnable() {
            @Override
            public void run(Session session) {
                HashMap<String, Object> payload = new HashMap<>();
                payload.put("app_id", session.appConfiguration.appId);
                payload.put("user_id", session.userId());
                payload.put("platform_id", notif.teakNotifId);

                new Request("/notification_received", payload, session).run();
            }
        });
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_OPENED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();

        // Cancel any updates pending
        TeakNotification.cancel(context, bundle.getInt("platformId"));

        // Launch the app
        if (!bundle.getBoolean("noAutolaunch")) {
            if (Teak.isDebug) {
                Log.d(LOG_TAG,
                        "Notification (" + bundle.getString("teakNotifId") + ") opened, auto-launching app.");
            }
            Intent launchIntent = context.getPackageManager()
                    .getLaunchIntentForPackage(context.getPackageName());
            launchIntent.addCategory("android.intent.category.LAUNCHER");
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            launchIntent.putExtras(bundle);
            if (bundle.getString("deepLink") != null) {
                launchIntent.setData(Uri.parse(bundle.getString("deepLink")));
            }
            context.startActivity(launchIntent);
        } else {
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Notification (" + bundle.getString("teakNotifId")
                        + ") opened, NOT auto-launching app (noAutoLaunch flag present, and set to true).");
            }
        }

        // Send broadcast
        if (Teak.localBroadcastManager != null) {
            Intent broadcastEvent = new Intent(TeakNotification.LAUNCHED_FROM_NOTIFICATION_INTENT);
            broadcastEvent.putExtras(bundle);
            Teak.localBroadcastManager.sendBroadcast(broadcastEvent);
        }
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_CLEARED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();
        TeakNotification.cancel(context, bundle.getInt("platformId"));
    }

}

From source file:com.mikecorrigan.bohrium.pubsub.RegistrationClient.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v(TAG, "onStartCommand: intent=" + intent + ", extras=" + Utils.bundleToString(intent.getExtras())
            + ", flags=" + flags + ", startId=" + startId);

    if (intent.getAction().equals(C2DM_INTENT_REGISTRATION)) {
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_REGISTRATION_RESPONSE, intent));
        GCMBroadcastReceiver.completeWakefulIntent(intent);
    } else if (intent.getAction().equals(C2DM_INTENT_RECEIVE)) {
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_MESSAGE, intent));
        GCMBroadcastReceiver.completeWakefulIntent(intent);
    } else if (intent.getAction().equals(C2DM_INTENT_RETRY)) {
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_RETRY_REGISTRATION, intent));
        GCMBroadcastReceiver.completeWakefulIntent(intent);
    } else if (intent.getAction().equals(Intent.ACTION_MAIN)) {
        if (mConfiguration == null) {
            mConfiguration = intent.getExtras();
        }//  w ww  .  jav a 2 s .c  o m

        mHandler.sendEmptyMessage(EVENT_INITIALIZE);
    } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
        mHandler.sendEmptyMessage(EVENT_UNINITIALIZE);
    }

    return RegistrationClient.START_STICKY;
}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

private void requestLicense() {
    if (TextUtils.isEmpty(LicenseUtils.getLicenseName(this))) {
        Intent intent = new Intent(PreventIntent.ACTION_CHECK_LICENSE,
                Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
        intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
        sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, new BroadcastReceiver() {
            @Override/*w ww. ja v  a  2  s .co  m*/
            public void onReceive(Context context, Intent intent) {
                if (PreventIntent.ACTION_CHECK_LICENSE.equals(intent.getAction()) && getResultCode() != 1) {
                    request = LicenseUtils.requestLicense(UserGuideActivity.this, null, getResultData());
                }
            }
        }, null, 0, null, null);
    }
}

From source file:com.aware.utils.WebserviceHelper.java

@Override
protected void onHandleIntent(Intent intent) {

    WEBSERVER = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER);
    DEVICE_ID = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID);
    DEBUG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true");
    DATABASE_TABLE = intent.getStringExtra(EXTRA_TABLE);
    TABLES_FIELDS = intent.getStringExtra(EXTRA_FIELDS);
    CONTENT_URI = Uri.parse(intent.getStringExtra(EXTRA_CONTENT_URI));

    //Fixed: not using webservices
    if (WEBSERVER.length() == 0)
        return;//from ww  w .  ja va 2s  .co m

    if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_SYNC_TABLE)) {

        //Check if we should do this only over Wi-Fi
        boolean wifi_only = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY)
                .equals("true");
        if (wifi_only) {
            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo active_network = cm.getActiveNetworkInfo();
            if (active_network != null && active_network.getType() != ConnectivityManager.TYPE_WIFI) {
                if (DEBUG) {
                    Log.i("AWARE", "User not connected to Wi-Fi, skipping data sync.");
                }
                return;
            }
        }

        //Check first if we have database table remotely, otherwise create it!
        ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>();
        fields.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
        fields.add(new BasicNameValuePair(EXTRA_FIELDS, TABLES_FIELDS));

        //Create table if doesn't exist on the remote webservice server
        HttpResponse response = new Https(getApplicationContext())
                .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/create_table", fields);
        if (response != null && response.getStatusLine().getStatusCode() == 200) {
            if (DEBUG) {
                HttpResponse copy = response;
                try {
                    if (DEBUG)
                        Log.d(Aware.TAG, EntityUtils.toString(copy.getEntity()));
                } catch (ParseException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            String[] columnsStr = new String[] {};
            Cursor columnsDB = getContentResolver().query(CONTENT_URI, null, null, null, null);
            if (columnsDB != null && columnsDB.moveToFirst()) {
                columnsStr = columnsDB.getColumnNames();
                if (DEBUG)
                    Log.d(Aware.TAG, "Total records on " + DATABASE_TABLE + ": " + columnsDB.getCount());
            }
            if (columnsDB != null && !columnsDB.isClosed())
                columnsDB.close();

            try {
                ArrayList<NameValuePair> request = new ArrayList<NameValuePair>();
                request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));

                //check the latest entry in remote database
                HttpResponse latest = new Https(getApplicationContext())
                        .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/latest", request);
                if (latest == null)
                    return;

                String data = "[]";
                try {
                    data = EntityUtils.toString(latest.getEntity());
                } catch (IllegalStateException e) {
                    Log.d(Aware.TAG, "Unable to connect to webservices...");
                }

                if (DEBUG) {
                    Log.d(Aware.TAG, "Webservice response: " + data);
                }

                //If in a study, get from joined date onwards
                String study_condition = "";
                if (Aware.getSetting(getApplicationContext(), "study_id").length() > 0
                        && Aware.getSetting(getApplicationContext(), "study_start").length() > 0) {
                    String study_start = Aware.getSetting(getApplicationContext(), "study_start");
                    study_condition = " AND timestamp > " + Long.parseLong(study_start);
                }
                if (DATABASE_TABLE.equalsIgnoreCase("aware_device"))
                    study_condition = "";

                JSONArray remoteData = new JSONArray(data);

                Cursor context_data;
                if (remoteData.length() == 0) {
                    if (exists(columnsStr, "double_end_timestamp")) {
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "double_end_timestamp != 0" + study_condition, null, "timestamp ASC");
                    } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) {
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "double_esm_user_answer_timestamp != 0" + study_condition, null,
                                "timestamp ASC");
                    } else {
                        context_data = getContentResolver().query(CONTENT_URI, null, "1" + study_condition,
                                null, "timestamp ASC");
                    }
                } else {
                    long last = 0;
                    if (exists(columnsStr, "double_end_timestamp")) {
                        last = remoteData.getJSONObject(0).getLong("double_end_timestamp");
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "timestamp > " + last + " AND double_end_timestamp != 0" + study_condition,
                                null, "timestamp ASC");
                    } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) {
                        last = remoteData.getJSONObject(0).getLong("double_esm_user_answer_timestamp");
                        context_data = getContentResolver().query(
                                CONTENT_URI, null, "timestamp > " + last
                                        + " AND double_esm_user_answer_timestamp != 0" + study_condition,
                                null, "timestamp ASC");
                    } else {
                        last = remoteData.getJSONObject(0).getLong("timestamp");
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "timestamp > " + last + study_condition, null, "timestamp ASC");
                    }
                }

                JSONArray context_data_entries = new JSONArray();
                if (context_data != null && context_data.moveToFirst()) {
                    if (DEBUG)
                        Log.d(Aware.TAG, "Uploading " + context_data.getCount() + " from " + DATABASE_TABLE);

                    do {
                        JSONObject entry = new JSONObject();

                        String[] columns = context_data.getColumnNames();
                        for (String c_name : columns) {

                            //Skip local database ID
                            if (c_name.equals("_id"))
                                continue;

                            if (c_name.equals("timestamp") || c_name.contains("double")) {
                                entry.put(c_name, context_data.getDouble(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("float")) {
                                entry.put(c_name, context_data.getFloat(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("long")) {
                                entry.put(c_name, context_data.getLong(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("blob")) {
                                entry.put(c_name, context_data.getBlob(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("integer")) {
                                entry.put(c_name, context_data.getInt(context_data.getColumnIndex(c_name)));
                            } else {
                                entry.put(c_name, context_data.getString(context_data.getColumnIndex(c_name)));
                            }
                        }
                        context_data_entries.put(entry);

                        if (context_data_entries.length() == 1000) {
                            request = new ArrayList<NameValuePair>();
                            request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
                            request.add(new BasicNameValuePair("data", context_data_entries.toString()));
                            new Https(getApplicationContext())
                                    .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request);

                            context_data_entries = new JSONArray();
                        }
                    } while (context_data.moveToNext());

                    if (context_data_entries.length() > 0) {
                        request = new ArrayList<NameValuePair>();
                        request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
                        request.add(new BasicNameValuePair("data", context_data_entries.toString()));
                        new Https(getApplicationContext())
                                .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request);
                    }
                } else {
                    if (DEBUG)
                        Log.d(Aware.TAG,
                                "Nothing new in " + DATABASE_TABLE + "!" + " URI=" + CONTENT_URI.toString());
                }

                if (context_data != null && !context_data.isClosed())
                    context_data.close();

            } catch (ParseException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //Clear database table remotely
    if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_CLEAR_TABLE)) {
        ArrayList<NameValuePair> request = new ArrayList<NameValuePair>();
        request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
        new Https(getApplicationContext()).dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/clear_table", request);
    }
}

From source file:aarddict.android.ArticleViewActivity.java

@Override
public boolean onSearchRequested() {
    Intent intent = getIntent();
    String action = intent == null ? null : intent.getAction();
    if (action != null) {
        String word = null;//from   w  ww .j a v  a 2s .  c om
        if (action.equals(Intent.ACTION_SEARCH)) {
            word = intent.getStringExtra("query");
        } else if (action.equals(Intent.ACTION_SEND)) {
            word = intent.getStringExtra(Intent.EXTRA_TEXT);
        }
        if (word != null) {
            Intent next = new Intent();
            next.setClass(this, LookupActivity.class);
            next.setAction(Intent.ACTION_SEARCH);
            next.putExtra(SearchManager.QUERY, word);
            startActivity(next);
        }
    }
    finish();
    return true;
}

From source file:org.peterbaldwin.vlcremote.app.PlaybackActivity.java

@Override
protected void onNewIntent(Intent intent) {
    String host = intent.getStringExtra(Intents.EXTRA_REMOTE_HOST);
    if (host != null) {
        int port = intent.getIntExtra(Intents.EXTRA_REMOTE_PORT, 8080);
        String authority = host + ":" + port;
        changeServer(authority);/*from w  ww . jav a  2s .  com*/
    }

    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) || Intents.ACTION_REMOTE_VIEW.equals(action)
            || Intents.ACTION_VIEW.equals(action)) {
        Uri data = intent.getData();
        if (data != null) {
            changeInput(data.toString());
        }
    } else if (Intent.ACTION_SEARCH.equals(action)) {
        String input = intent.getStringExtra(SearchManager.QUERY);
        changeInput(input);
    }
}

From source file:com.test.onesignal.MainOneSignalClassRunner.java

@Test
public void testOpeningLaunchUrl() throws Exception {
    // Clear app launching normally
    Shadows.shadowOf(blankActivity).getNextStartedActivity();

    // No OneSignal init here to test case where it is located in an Activity.

    OneSignal.handleNotificationOpened(blankActivity, new JSONArray(
            "[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\", \"u\": \"http://google.com\" } }]"),
            false);/*from   ww  w  . ja v a2  s  .  c om*/

    Intent intent = Shadows.shadowOf(blankActivity).getNextStartedActivity();
    Assert.assertEquals("android.intent.action.VIEW", intent.getAction());
    Assert.assertEquals("http://google.com", intent.getData().toString());
    Assert.assertNull(Shadows.shadowOf(blankActivity).getNextStartedActivity());
}

From source file:ca.mudar.parkcatcher.ui.activities.MainActivity.java

@Override
public void onResume() {
    super.onResume();

    // Check Playservices status
    if (isPlayservicesOutdated) {
        if (GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(getApplicationContext()) != ConnectionResult.SUCCESS) {
            // Still out of date, interrupt onResume()
            disableLocationUpdates();// w  w w.j a v  a2 s  .c  om
        } else {
            // Playservice updated, display message and restart activity
            parkingApp.showToastText(R.string.toast_playservices_restart, Toast.LENGTH_LONG);
            final Intent intent = getIntent();
            this.finish();
            startActivity(intent);
        }
        return;
    }

    if (!ConnectionHelper.hasConnection(this)) {
        ConnectionHelper.showDialogNoConnection(this);
    }

    // TODO Optimize this using savedInstanceState to avoid reload of
    // identical data onResume
    final Intent intent = getIntent();
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        updateParkingTimeFromUri(intent.getData());

        updateParkingTimeTitle();
        updateParkingDateButton();
        updateParkingTimeButton();
        updateParkingDurationButton();
        mFavoritesFragment.refreshList();
    }

    // if
    // (getSupportActionBar().getSelectedTab().getTag().equals(Const.TAG_TABS_MAP)
    // || isCenterOnMyLocation) {
    if (initLocation != null || isCenterOnMyLocation) {
        try {
            mMapFragment.setMapCenter(initLocation);
            isCenterOnMyLocation = false;

            final ActionBar ab = getSupportActionBar();
            if (ab.getSelectedTab().getPosition() != Const.TABS_INDEX_MAP) {
                ab.setSelectedNavigationItem(Const.TABS_INDEX_MAP);
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }
    // }

}

From source file:com.hhunj.hhudata.ForegroundService.java

void handleCommand(Intent intent) {
    if (intent == null) {
        return;//from   w ww .  j  a v a 2s  . co m
    }
    if (ACTION_FOREGROUND.equals(intent.getAction())) {
        // In this sample, we'll use the same text for the ticker and the
        // expanded notification
        CharSequence text = getText(R.string.foreground_service_started);

        // Set the icon, scrolling text and timestamp
        Notification notification = new Notification(R.drawable.stat_sample, text, System.currentTimeMillis());

        // The PendingIntent to launch our activity if the user selects this
        // notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainTab.class), 0);//

        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent);

        startForegroundCompat(R.string.foreground_service_started, notification);

    }
    /*
     * else if (ACTION_BACKGROUND.equals(intent.getAction())) {
     * stopForegroundCompat(R.string.foreground_service_started); }
     */

}