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:jp.co.ipublishing.esnavi.activities.ShelterDetailActivity.java

/**
 * ?/*from  w  w w.j a  v a2  s.c  om*/
 */
private void startNavigation(@Nullable final Shelter shelter) {
    if (shelter == null) {
        // TODO: ?????
        return;
    }

    // TODO: ????
    final Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setClassName("com.google.android.apps.maps",
            "com.google.android.maps.driveabout.app.NavigationActivity");

    final Uri uri = Uri.parse(String.format("google.navigation:///?ll=%f,%f&q=%s&mode=w",
            shelter.getCoordinates().latitude, shelter.getCoordinates().longitude, shelter.getName()));

    intent.setData(uri);

    startActivity(intent);
}

From source file:com.snappy.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras,
        String messageData) {// w w  w. j ava  2  s.c  o m

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);

        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());

        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setLatestEventInfo(this, context.getString(R.string.app_name), messageData, pendingIntent);

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);

    }

    Log.i(LOG_TAG, message);
    Log.i(LOG_TAG, fromName);

}

From source file:com.zira.registration.DocumentUploadActivity.java

protected void selectImage() {

    final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(DocumentUploadActivity.this);
    builder.setTitle("Add Photo!");
    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override/* ww  w.  ja v  a  2s .  c  om*/
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                // Ensure that there's a camera activity to handle the intent
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    // Create the File where the photo should go
                    File photoFile = null;
                    try {
                        mCurrentPhotoPath = Util.createImageFile();
                        photoFile = new File(mCurrentPhotoPath);
                    } catch (Exception ex) {
                        // Error occurred while creating the File
                        ex.printStackTrace();
                    }
                    // Continue only if the File was successfully created
                    if (photoFile != null) {
                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                        startActivityForResult(takePictureIntent, 1);
                    }
                }
            } else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();

}

From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java

public void createDeskShortCut() {
    // ????/*from  w w w.  j av  a  2  s. c  o  m*/
    SharedPreferenceUtil.editShortCut(true);
    Intent shortcutIntent = new Intent();
    shortcutIntent.setClass(this, SplashActivity.class);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    shortcutIntent.setAction("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");

    Intent resultIntent = new Intent();
    resultIntent.putExtra("duplicate", false);
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    resultIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    sendBroadcast(resultIntent);
    resultIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(resultIntent);
}

From source file:com.beesham.popularmovies.DetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_details_view, container, false);
    ButterKnife.bind(this, rootView);

    mTrailerList = new ArrayList();
    mReviewsList = new ArrayList();

    mReviewAdapter = new ReviewAdapter(getActivity(), mReviewsList);
    reviewsListView.setAdapter(mReviewAdapter);
    reviewsListView.setEmptyView(emptyReviewsTextView);

    mTrailersAdapter = new TrailersAdapter(getActivity(), mTrailerList);
    trailersListView.setAdapter(mTrailersAdapter);
    trailersListView.setEmptyView(emptyTrailersTextView);
    trailersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from  w  w w  . j av  a  2  s. c  om
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);

            String movieBaseYoutubeUrl = getString(R.string.movies_base_youtube_url,
                    ((Trailer) mTrailerList.get(i)).getTrailerKey());

            intent.setData(Uri.parse(movieBaseYoutubeUrl));
            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);
            }
        }
    });

    favoriteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (checkForFavorite()) {
                removeFavorite();
                favoriteButton.setText(R.string.mark_favorite);
            } else {
                insertFavoriteMovie();
                favoriteButton.setText(R.string.mark_unfavorite);
            }
        }
    });

    Bundle args = getArguments();
    if (args != null) {
        mUri = args.getParcelable(DetailsFragment.DETAIL_URI);
    }

    if (savedInstanceState != null && args.containsKey(DetailsFragment.DETAIL_URI)) {
        mUri = args.getParcelable(DetailsFragment.DETAIL_URI);
    }

    return rootView;
}

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

@Override
protected void onHandleIntent(Intent intent) {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;/*from www. j a va  2  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[] { "mountain_passes" }, 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();
        buildWeatherPhrases();

        try {
            URL url = new URL(MOUNTAIN_PASS_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 mDateUpdated = "";
            String jsonFile = "";
            String line;
            while ((line = in.readLine()) != null)
                jsonFile += line;
            in.close();

            JSONObject obj = new JSONObject(jsonFile);
            JSONObject result = obj.getJSONObject("GetMountainPassConditionsResult");
            JSONArray passConditions = result.getJSONArray("PassCondition");
            String weatherCondition;
            Integer weather_image;
            Integer forecast_weather_image;
            List<ContentValues> passes = new ArrayList<ContentValues>();

            int numConditions = passConditions.length();
            for (int j = 0; j < numConditions; j++) {
                JSONObject pass = passConditions.getJSONObject(j);
                ContentValues passData = new ContentValues();
                weatherCondition = pass.getString("WeatherCondition");
                weather_image = getWeatherImage(weatherPhrases, weatherCondition);

                String tempDate = pass.getString("DateUpdated");

                try {
                    tempDate = tempDate.replace("[", "");
                    tempDate = tempDate.replace("]", "");

                    String[] a = tempDate.split(",");
                    StringBuilder sb = new StringBuilder();
                    for (int m = 0; m < 5; m++) {
                        sb.append(a[m]);
                        sb.append(",");
                    }
                    tempDate = sb.toString().trim();
                    tempDate = tempDate.substring(0, tempDate.length() - 1);
                    Date date = parseDateFormat.parse(tempDate);
                    mDateUpdated = displayDateFormat.format(date);
                } catch (Exception e) {
                    Log.e(DEBUG_TAG, "Error parsing date: " + tempDate, e);
                    mDateUpdated = "N/A";
                }

                JSONArray forecasts = pass.getJSONArray("Forecast");
                JSONArray forecastItems = new JSONArray();

                int numForecasts = forecasts.length();
                for (int l = 0; l < numForecasts; l++) {
                    JSONObject forecast = forecasts.getJSONObject(l);

                    if (isNight(forecast.getString("Day"))) {
                        forecast_weather_image = getWeatherImage(weatherPhrasesNight,
                                forecast.getString("ForecastText"));
                    } else {
                        forecast_weather_image = getWeatherImage(weatherPhrases,
                                forecast.getString("ForecastText"));
                    }

                    forecast.put("weather_icon", forecast_weather_image);

                    if (l == 0) {
                        if (weatherCondition.equals("")) {
                            weatherCondition = forecast.getString("ForecastText").split("\\.")[0] + ".";
                            weather_image = forecast_weather_image;
                        }
                    }

                    forecastItems.put(forecast);
                }

                passData.put(MountainPasses.MOUNTAIN_PASS_ID, pass.getString("MountainPassId"));
                passData.put(MountainPasses.MOUNTAIN_PASS_NAME, pass.getString("MountainPassName"));
                passData.put(MountainPasses.MOUNTAIN_PASS_WEATHER_ICON, weather_image);
                passData.put(MountainPasses.MOUNTAIN_PASS_FORECAST, forecastItems.toString());
                passData.put(MountainPasses.MOUNTAIN_PASS_WEATHER_CONDITION, weatherCondition);
                passData.put(MountainPasses.MOUNTAIN_PASS_DATE_UPDATED, mDateUpdated);
                passData.put(MountainPasses.MOUNTAIN_PASS_CAMERA, pass.getString("Cameras"));
                passData.put(MountainPasses.MOUNTAIN_PASS_ELEVATION, pass.getString("ElevationInFeet"));
                passData.put(MountainPasses.MOUNTAIN_PASS_TRAVEL_ADVISORY_ACTIVE,
                        pass.getString("TravelAdvisoryActive"));
                passData.put(MountainPasses.MOUNTAIN_PASS_ROAD_CONDITION, pass.getString("RoadCondition"));
                passData.put(MountainPasses.MOUNTAIN_PASS_TEMPERATURE,
                        pass.getString("TemperatureInFahrenheit"));
                JSONObject restrictionOne = pass.getJSONObject("RestrictionOne");
                passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_ONE,
                        restrictionOne.getString("RestrictionText"));
                passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_ONE_DIRECTION,
                        restrictionOne.getString("TravelDirection"));
                JSONObject restrictionTwo = pass.getJSONObject("RestrictionTwo");
                passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_TWO,
                        restrictionTwo.getString("RestrictionText"));
                passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_TWO_DIRECTION,
                        restrictionTwo.getString("TravelDirection"));

                if (starred.contains(Integer.parseInt(pass.getString("MountainPassId")))) {
                    passData.put(MountainPasses.MOUNTAIN_PASS_IS_STARRED, 1);
                }

                passes.add(passData);

            }

            // Purge existing mountain passes covered by incoming data
            resolver.delete(MountainPasses.CONTENT_URI, null, null);
            // Bulk insert all the new mountain passes
            resolver.bulkInsert(MountainPasses.CONTENT_URI, passes.toArray(new ContentValues[passes.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[] { "mountain_passes" });

            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.MOUNTAIN_PASSES_RESPONSE");
    broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
    broadcastIntent.putExtra("responseString", responseString);
    sendBroadcast(broadcastIntent);
}

From source file:com.github.opengarageapp.activity.MainActivity.java

private void startGetStateService(int door) {
    Intent serviceIntent = new Intent(MainActivity.this, GarageStateService.class);

    switch (door) {
    case 1:/*from   w ww .j  a v a2 s. c  o m*/
        serviceIntent.setAction(GarageService.INTENT_STATE1);
        startService(serviceIntent);
    case 2:
        serviceIntent.setAction(GarageService.INTENT_STATE2);
        startService(serviceIntent);
    }
}

From source file:com.github.opengarageapp.activity.MainActivity.java

private void startToggleService(int door) {
    Intent serviceIntent = new Intent(MainActivity.this, GarageToggleService.class);

    switch (door) {
    case 1://from w ww  .java 2  s.  c  om
        serviceIntent.setAction(GarageService.INTENT_TOGGLE1);
        startService(serviceIntent);
    case 2:
        serviceIntent.setAction(GarageService.INTENT_TOGGLE2);
        startService(serviceIntent);
    }
}

From source file:com.github.opengarageapp.activity.MainActivity.java

private void startCloseService(int door) {
    Intent serviceIntent = new Intent(MainActivity.this, GarageToggleService.class);

    switch (door) {
    case 1:/*  ww w . j  a v a  2 s .  com*/
        serviceIntent.setAction(GarageService.INTENT_CLOSE1);
        startService(serviceIntent);
    case 2:
        serviceIntent.setAction(GarageService.INTENT_CLOSE2);
        startService(serviceIntent);
    }
}

From source file:com.khoahuy.phototag.HomeActivity.java

private void displayNFCItem(String nfcid) {
    Intent myIntent = new Intent(this, ViewImageActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString("nfcid", nfcid);
    myIntent.setAction(Intent.ACTION_VIEW);
    myIntent.putExtra("MyPackage", bundle);
    startActivity(myIntent);//w w w  .  j  a  v a2  s .  c o m
}