Example usage for android.content Intent setAction

List of usage examples for android.content Intent setAction

Introduction

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

Prototype

public @NonNull Intent setAction(@Nullable String action) 

Source Link

Document

Set the general action to be performed.

Usage

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppReferenceObj.java

@Override
public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String packageName = obj.optString(PACKAGE_NAME);
    String arg = obj.optString(ARG);
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.putExtra(AppState.EXTRA_APPLICATION_ARGUMENT, arg);
    launch.putExtra("creator", false);
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launch.setPackage(packageName);/*from   w w w.j  a va  2 s.  c  o m*/
    final PackageManager mgr = context.getPackageManager();
    List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0);
    if (resolved == null || resolved.size() == 0) {
        Toast.makeText(context, "Could not find application to handle invite", Toast.LENGTH_SHORT).show();
        return;
    }
    ActivityInfo info = resolved.get(0).activityInfo;
    launch.setComponent(new ComponentName(info.packageName, info.name));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);

    (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received from " + from.name,
            "Click to launch application.", contentIntent);
}

From source file:net.ccghe.emocha.services.ServerService.java

private void updateGps() {
    Intent i = new Intent();
    i.setAction(GpsService.INTENT_FILTER);
    sendBroadcast(i);
}

From source file:com.xtensive.plugins.pdfviewer.PDFViewer.java

/**
  * Display a MuPDF with the specified URL.
  *//ww  w. ja v a  2 s .  com
  * @param path           The path to load.
  * @return               "" if ok, or error message.
  */
public String openPDF(final String path) {
    try {

        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                Context context = cordova.getActivity().getApplicationContext();

                Intent intent = new Intent(context, MuPDFActivity.class);
                intent.setAction(Intent.ACTION_VIEW);
                //String fileName = Environment.getExternalStorageDirectory().toString() + "/" + path;
                String fileName = path;

                Log.d(LOG_TAG, "DEBUG load: " + fileName);
                intent.setData(Uri.parse(fileName));
                cordova.getActivity().startActivityForResult(intent, XRI_LINK_CLIKED);
            }
        });

        return "";
    } catch (android.content.ActivityNotFoundException e) {

        Log.e(LOG_TAG, "Error loading url " + path + ":" + e.toString());
        return e.toString();
    }
}

From source file:com.phonegap.plugins.discoverscanar.DiscoverScanAR.java

public void arscan(String json_file) {

    Intent intentARScan = new Intent();
    intentARScan.setAction(Intent.ACTION_VIEW);

    if (json_file == null) {
        json_file = "hamilton.json";
    }/*from  w  w  w .  j  av a 2  s . c o m*/

    // Used to be hardwired to: "http://www.cs.waikato.ac.nz/~davidb/tipple/uni-mixare-locdata.json"
    intentARScan.setDataAndType(Uri.parse("file:///sdcard/tipple-store/geodata/" + json_file),
            "application/mixare-json");
    this.cordova.startActivityForResult((CordovaPlugin) this, intentARScan, REQUEST_ARSCAN_CODE);
}

From source file:com.sidekickApp.PusherClass.java

private void startDecayTimer() {
    log("startDecayTimer()");
    decayTimer = new Timer("decayTimer", true);
    long initialDelay = 0;
    long interval = 250;

    decayTimer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            // calculate decay
            interest = interest * decayFactor;
            if (interest > 100) {
                interest = 100;/*  w  ww.ja  va2  s  .  c  om*/
            }
            if (interest < 0.1) {
                interest = 0;
            }
            log("Pusher: interest = " + interest);

            Intent i = new Intent();
            int interestI = (int) interest;
            i.putExtra("com.sidekickApp.interest", interestI);
            i.setAction(AppState.SIDECAR_INTEREST);
            main.sendBroadcast(i);
        }
    }, initialDelay, interval);

}

From source file:gov.wa.wsdot.android.wsdot.service.BorderWaitSyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;//  ww w  . j  a v a2 s  .c o m
    long now = System.currentTimeMillis();
    boolean shouldUpdate = true;
    String responseString = "";

    /** 
     * Check the cache table for the last time data was downloaded. If we are within
     * the allowed time period, don't sync, otherwise get fresh data from the server.
     */
    try {
        cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED },
                Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "border_wait" }, null);

        if (cursor != null && cursor.moveToFirst()) {
            long lastUpdated = cursor.getLong(0);
            //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS;
            //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min");
            shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.MINUTE_IN_MILLIS));
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    // Ability to force a refresh of camera data.
    boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false);

    if (shouldUpdate || forceUpdate) {
        List<Integer> starred = new ArrayList<Integer>();

        starred = getStarred();

        try {
            URL url = new URL(BORDER_WAIT_URL);
            URLConnection urlConn = url.openConnection();

            BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String jsonFile = "";
            String line;

            while ((line = in.readLine()) != null)
                jsonFile += line;
            in.close();

            JSONObject obj = new JSONObject(jsonFile);
            JSONObject result = obj.getJSONObject("waittimes");
            JSONArray items = result.getJSONArray("items");
            List<ContentValues> times = new ArrayList<ContentValues>();

            int numItems = items.length();
            for (int j = 0; j < numItems; j++) {
                JSONObject item = items.getJSONObject(j);
                ContentValues timesValues = new ContentValues();
                timesValues.put(BorderWait.BORDER_WAIT_ID, item.getInt("id"));
                timesValues.put(BorderWait.BORDER_WAIT_TITLE, item.getString("name"));
                timesValues.put(BorderWait.BORDER_WAIT_UPDATED, item.getString("updated"));
                timesValues.put(BorderWait.BORDER_WAIT_LANE, item.getString("lane"));
                timesValues.put(BorderWait.BORDER_WAIT_ROUTE, item.getInt("route"));
                timesValues.put(BorderWait.BORDER_WAIT_DIRECTION, item.getString("direction"));
                timesValues.put(BorderWait.BORDER_WAIT_TIME, item.getInt("wait"));

                if (starred.contains(item.getInt("id"))) {
                    timesValues.put(BorderWait.BORDER_WAIT_IS_STARRED, 1);
                }

                times.add(timesValues);

            }

            // Purge existing border wait times covered by incoming data
            resolver.delete(BorderWait.CONTENT_URI, null, null);
            // Bulk insert all the new travel times
            resolver.bulkInsert(BorderWait.CONTENT_URI, times.toArray(new ContentValues[times.size()]));
            // Update the cache table with the time we did the update
            ContentValues values = new ContentValues();
            values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis());
            resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?",
                    new String[] { "border_wait" });

            responseString = "OK";

        } catch (Exception e) {
            Log.e(DEBUG_TAG, "Error: " + e.getMessage());
            responseString = e.getMessage();
        }
    } else {
        responseString = "NOP";
    }

    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.BORDER_WAIT_RESPONSE");
    broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
    broadcastIntent.putExtra("responseString", responseString);
    sendBroadcast(broadcastIntent);

}

From source file:edu.mines.letschat.GcmIntentService.java

protected PendingIntent getDeleteIntent() {
    Intent resultBroadCastIntent = new Intent();
    resultBroadCastIntent.setAction("deletion");
    resultBroadCastIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    resultBroadCastIntent.addCategory(Intent.CATEGORY_DEFAULT);
    sendBroadcast(resultBroadCastIntent);
    return PendingIntent.getBroadcast(getBaseContext(), 0, resultBroadCastIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;//from w w w  .  j a v  a 2s  . c om
    long now = System.currentTimeMillis();
    boolean shouldUpdate = true;
    String responseString = "";
    DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a");

    /** 
     * Check the cache table for the last time data was downloaded. If we are within
     * the allowed time period, don't sync, otherwise get fresh data from the server.
     */
    try {
        cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED },
                Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "ferries_terminal_sailing_space" }, null);

        if (cursor != null && cursor.moveToFirst()) {
            long lastUpdated = cursor.getLong(0);
            shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.SECOND_IN_MILLIS));
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    // Ability to force a refresh of camera data.
    boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false);

    if (shouldUpdate || forceUpdate) {
        List<Integer> starred = new ArrayList<Integer>();

        starred = getStarred();

        try {
            URL url = new URL(TERMINAL_SAILING_SPACE_URL);
            URLConnection urlConn = url.openConnection();

            BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String jsonFile = "";
            String line;

            while ((line = in.readLine()) != null)
                jsonFile += line;
            in.close();

            JSONArray array = new JSONArray(jsonFile);
            List<ContentValues> terminal = new ArrayList<ContentValues>();

            int numItems = array.length();
            for (int j = 0; j < numItems; j++) {
                JSONObject item = array.getJSONObject(j);
                ContentValues sailingSpaceValues = new ContentValues();
                sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ID, item.getInt("TerminalID"));
                sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_NAME,
                        item.getString("TerminalName"));
                sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ABBREV,
                        item.getString("TerminalAbbrev"));
                sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_DEPARTING_SPACES,
                        item.getString("DepartingSpaces"));
                sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_LAST_UPDATED,
                        dateFormat.format(new Date(System.currentTimeMillis())));

                if (starred.contains(item.getInt("TerminalID"))) {
                    sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_IS_STARRED, 1);
                }

                terminal.add(sailingSpaceValues);
            }

            // Purge existing terminal sailing space items covered by incoming data
            resolver.delete(FerriesTerminalSailingSpace.CONTENT_URI, null, null);
            // Bulk insert all the new terminal sailing space items
            resolver.bulkInsert(FerriesTerminalSailingSpace.CONTENT_URI,
                    terminal.toArray(new ContentValues[terminal.size()]));
            // Update the cache table with the time we did the update
            ContentValues values = new ContentValues();
            values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis());
            resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?",
                    new String[] { "ferries_terminal_sailing_space" });

            responseString = "OK";

        } catch (Exception e) {
            Log.e(TAG, "Error: " + e.getMessage());
            responseString = e.getMessage();
        }
    } else {
        responseString = "NOP";
    }

    Intent broadcastIntent = new Intent();
    broadcastIntent
            .setAction("gov.wa.wsdot.android.wsdot.intent.action.FERRIES_TERMINAL_SAILING_SPACE_RESPONSE");
    broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
    broadcastIntent.putExtra("responseString", responseString);
    sendBroadcast(broadcastIntent);
}

From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java

public void continueOnCreate() {
    G.init(this);
    db = new Database(this);

    twitBox = (TextView) findViewById(R.id.twitbox);
    settingsIcon = (ImageView) findViewById(R.id.settings);
    twitBox.setText("Loading");

    twitBox.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            speakTwit();/*from  ww w.  j  a va  2s.  c  o  m*/
        }
    });

    settingsIcon.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent iSettings = new Intent();
            iSettings.setClassName("com.altcanvas.twitspeak", SettingsActivity.class.getName());
            TwitSpeakActivity.this.startActivity(iSettings);
        }
    });

    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, G.REQCODE_CHECK_TTS);
}

From source file:gov.wa.wsdot.android.wsdot.service.TravelTimesSyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;/*from  w w w  .  ja  v  a2  s  .  c om*/
    long now = System.currentTimeMillis();
    boolean shouldUpdate = true;
    String responseString = "";

    /** 
     * Check the cache table for the last time data was downloaded. If we are within
     * the allowed time period, don't sync, otherwise get fresh data from the server.
     */
    try {
        cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED },
                Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "travel_times" }, null);

        if (cursor != null && cursor.moveToFirst()) {
            long lastUpdated = cursor.getLong(0);
            //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS;
            //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min");
            shouldUpdate = (Math.abs(now - lastUpdated) > (5 * DateUtils.MINUTE_IN_MILLIS));
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    // Ability to force a refresh of camera data.
    boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false);

    if (shouldUpdate || forceUpdate) {
        List<Integer> starred = new ArrayList<Integer>();

        starred = getStarred();

        try {
            URL url = new URL(TRAVEL_TIMES_URL);
            URLConnection urlConn = url.openConnection();

            BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream());
            GZIPInputStream gzin = new GZIPInputStream(bis);
            InputStreamReader is = new InputStreamReader(gzin);
            BufferedReader in = new BufferedReader(is);

            String jsonFile = "";
            String line;

            while ((line = in.readLine()) != null)
                jsonFile += line;
            in.close();

            JSONObject obj = new JSONObject(jsonFile);
            JSONObject result = obj.getJSONObject("traveltimes");
            JSONArray items = result.getJSONArray("items");
            List<ContentValues> times = new ArrayList<ContentValues>();

            int numItems = items.length();
            for (int j = 0; j < numItems; j++) {
                JSONObject item = items.getJSONObject(j);
                ContentValues timesValues = new ContentValues();
                timesValues.put(TravelTimes.TRAVEL_TIMES_TITLE, item.getString("title"));
                timesValues.put(TravelTimes.TRAVEL_TIMES_CURRENT, item.getInt("current"));
                timesValues.put(TravelTimes.TRAVEL_TIMES_AVERAGE, item.getInt("average"));
                timesValues.put(TravelTimes.TRAVEL_TIMES_DISTANCE, item.getString("distance") + " miles");
                timesValues.put(TravelTimes.TRAVEL_TIMES_ID, Integer.parseInt(item.getString("routeid")));
                timesValues.put(TravelTimes.TRAVEL_TIMES_UPDATED, item.getString("updated"));

                if (starred.contains(Integer.parseInt(item.getString("routeid")))) {
                    timesValues.put(TravelTimes.TRAVEL_TIMES_IS_STARRED, 1);
                }

                times.add(timesValues);
            }

            // Purge existing travel times covered by incoming data
            resolver.delete(TravelTimes.CONTENT_URI, null, null);
            // Bulk insert all the new travel times
            resolver.bulkInsert(TravelTimes.CONTENT_URI, times.toArray(new ContentValues[times.size()]));
            // Update the cache table with the time we did the update
            ContentValues values = new ContentValues();
            values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis());
            resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?",
                    new String[] { "travel_times" });

            responseString = "OK";
        } catch (Exception e) {
            Log.e(DEBUG_TAG, "Error: " + e.getMessage());
            responseString = e.getMessage();
        }

    } else {
        responseString = "NOP";
    }

    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.TRAVEL_TIMES_RESPONSE");
    broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
    broadcastIntent.putExtra("responseString", responseString);
    sendBroadcast(broadcastIntent);
}