Example usage for android.content Intent addCategory

List of usage examples for android.content Intent addCategory

Introduction

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

Prototype

public @NonNull Intent addCategory(String category) 

Source Link

Document

Add a new category to the intent.

Usage

From source file:bg.mentormate.academy.reservations.activities.BroadcastNotifier.java

/**
 *
 * Uses LocalBroadcastManager to send an {@link android.content.Intent} containing {@code status}. The
 * {@link android.content.Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}.
 *
 * @param status {@link Integer} denoting a work request status
 *///from   w  w  w . j a  v a  2 s. co  m
public void broadcastIntentWithState(int status) {

    Intent localIntent = new Intent();

    // The Intent contains the custom broadcast action for this app
    localIntent.setAction(DBConstants.BROADCAST_ACTION);

    // Puts the status into the Intent
    localIntent.putExtra(DBConstants.EXTENDED_DATA_STATUS, status);
    localIntent.addCategory(Intent.CATEGORY_DEFAULT);

    // Broadcasts the Intent
    mBroadcaster.sendBroadcast(localIntent);

}

From source file:com.oakesville.mythling.MediaPagerActivity.java

@Override
public void onBackPressed() {
    if (EpgActivity.class.getName().equals(backTo) || FireTvEpgActivity.class.getName().equals(backTo)) {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);//w w  w  .j a v a  2  s  . c om
    } else if (modeSwitch) {
        modeSwitch = false;
        Intent intent = new Intent(this, MediaPagerActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    } else {
        super.onBackPressed();
    }
}

From source file:com.ce.skuniv.helpers.Notifications.java

public void displayNotification(String title, String text, boolean Sound, int Id, boolean isPresistant) {
    if (Id == 0) {
        Id = rnd.nextInt();/* ww w. j  a  v a 2  s.  co  m*/
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(title).setContentText(text);
    if (Sound)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // mBuilder.setOnlyAlertOnce(false);
    mBuilder.setTicker(title + ":" + text);
    mBuilder.setOngoing(isPresistant);
    mBuilder.setAutoCancel(true);

    // Intent notificationIntent = new Intent(context,
    // MainMultiWiiActivity.class);

    Intent notificationIntent = new Intent(context, MainMultiWiiActivity.class);
    // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You
    // need this if starting
    // the activity from a service
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

    //      mNotificationManager.notify(Id, mBuilder.build());
}

From source file:com.ezio.multiwii.helpers.Notifications.java

public void displayNotification(String title, String text, boolean Sound, int Id, boolean isPresistant) {
    if (Id == 0) {
        Id = rnd.nextInt();//from   w w w .j  av a  2  s  . c om
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(title).setContentText(text);
    if (Sound)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // mBuilder.setOnlyAlertOnce(false);
    mBuilder.setTicker(title + ":" + text);
    mBuilder.setOngoing(isPresistant);
    mBuilder.setAutoCancel(true);

    // Intent notificationIntent = new Intent(context,
    // MainMultiWiiActivity.class);

    Intent notificationIntent = new Intent(context, MainMultiWiiActivity.class);
    // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You
    // need this if starting
    // the activity from a service
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

    mNotificationManager.notify(Id, mBuilder.build());
}

From source file:com.chilliworks.chillisource.core.LocalNotificationReceiver.java

/**
 * Called when a local notification broad cast is received. Funnels the notification
 * into the app if open or into the notification bar if not
 * //from   ww w. ja  va  2  s.c o  m
 * @author Steven Hendrie
 * 
 * @param The context.
 * @param The intent.
 */
@SuppressWarnings("deprecation")
@Override
public void onReceive(Context in_context, Intent in_intent) {
    //evaluate whether or not the main engine activity is in the foreground
    boolean isAppInForeground = false;
    if (CSApplication.get() != null && CSApplication.get().isActive() == true) {
        isAppInForeground = true;
    }

    //if the main engine activity is in the foreground, simply pass the
    //notification into it. Otherwise display a notification.
    if (isAppInForeground == true) {
        final Intent intent = new Intent(in_intent.getAction());
        Bundle mapParams = in_intent.getExtras();
        Iterator<String> iter = mapParams.keySet().iterator();

        while (iter.hasNext()) {
            String strKey = iter.next();
            intent.putExtra(strKey, mapParams.get(strKey).toString());
        }

        LocalNotificationNativeInterface localNotificationNI = (LocalNotificationNativeInterface) CSApplication
                .get().getSystem(LocalNotificationNativeInterface.InterfaceID);
        if (localNotificationNI != null) {
            localNotificationNI.onNotificationReceived(intent);
        }
    } else {
        //aquire a wake lock
        if (s_wakeLock != null) {
            s_wakeLock.release();
        }

        PowerManager pm = (PowerManager) in_context.getSystemService(Context.POWER_SERVICE);
        s_wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "NotificationWakeLock");
        s_wakeLock.acquire();

        //pull out the information from the intent
        Bundle params = in_intent.getExtras();
        CharSequence title = params.getString(k_paramNameTitle);
        CharSequence text = params.getString(k_paramNameBody);
        int intentId = params.getInt(LocalNotification.k_paramNameNotificationId);

        int paramSize = params.size();
        String[] keys = new String[paramSize];
        String[] values = new String[paramSize];
        Iterator<String> iter = params.keySet().iterator();
        int paramNumber = 0;
        while (iter.hasNext()) {
            keys[paramNumber] = iter.next();
            values[paramNumber] = params.get(keys[paramNumber]).toString();
            ++paramNumber;
        }

        Intent openAppIntent = new Intent(in_context, CSActivity.class);
        openAppIntent.setAction("android.intent.action.MAIN");
        openAppIntent.addCategory("android.intent.category.LAUNCHER");
        openAppIntent.putExtra(k_appOpenedFromNotification, true);
        openAppIntent.putExtra(k_arrayOfKeysName, keys);
        openAppIntent.putExtra(k_arrayOfValuesName, values);
        openAppIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent sContentIntent = PendingIntent.getActivity(in_context, intentId, openAppIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        Bitmap largeIconBitmap = null;
        int LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context,
                ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify_large");

        //Use small icon if no large icon
        if (LargeIconID == 0) {
            LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context,
                    ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify");
        }

        if (LargeIconID > 0) {
            largeIconBitmap = BitmapFactory.decodeResource(in_context.getResources(), LargeIconID);
        }

        Notification notification = new NotificationCompat.Builder(in_context).setContentTitle(title)
                .setContentText(text)
                .setSmallIcon(ResourceHelper.GetDynamicResourceIDForField(in_context,
                        ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify"))
                .setLargeIcon(largeIconBitmap).setContentIntent(sContentIntent).build();

        NotificationManager notificationManager = (NotificationManager) in_context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(intentId, notification);
        Toast.makeText(in_context, text, Toast.LENGTH_LONG).show();
    }
}

From source file:com.core.base.js.UploadHandler.java

private Intent createDefaultOpenableIntent() {
    // Create and return a chooser with the default OPENABLE
    // actions including the camera, camcorder and sound
    // recorder where available.
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("*/*");

    Intent chooser = createChooserIntent();
    chooser.putExtra(Intent.EXTRA_INTENT, i);
    return chooser;
}

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

@SuppressLint("SimpleDateFormat")
@Override/*from   ww w.ja  va 2s .  c  o  m*/
protected void onHandleIntent(Intent intent) {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    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, projection, Caches.CACHE_TABLE_NAME + " LIKE ?",
                new String[] { "highway_alerts" }, 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();
        }
    }

    // Tapping the refresh button will force a data refresh.
    boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false);

    if (shouldUpdate || forceUpdate) {

        try {
            URL url = new URL(HIGHWAY_ALERTS_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("alerts");
            JSONArray items = result.getJSONArray("items");
            List<ContentValues> alerts = new ArrayList<ContentValues>();

            int numItems = items.length();
            for (int j = 0; j < numItems; j++) {
                JSONObject item = items.getJSONObject(j);
                JSONObject startRoadwayLocation = item.getJSONObject("StartRoadwayLocation");
                ContentValues alertData = new ContentValues();

                alertData.put(HighwayAlerts.HIGHWAY_ALERT_ID, item.getString("AlertID"));
                alertData.put(HighwayAlerts.HIGHWAY_ALERT_HEADLINE, item.getString("HeadlineDescription"));
                alertData.put(HighwayAlerts.HIGHWAY_ALERT_CATEGORY, item.getString("EventCategory"));
                alertData.put(HighwayAlerts.HIGHWAY_ALERT_PRIORITY, item.getString("Priority"));
                alertData.put(HighwayAlerts.HIGHWAY_ALERT_LATITUDE, startRoadwayLocation.getString("Latitude"));
                alertData.put(HighwayAlerts.HIGHWAY_ALERT_LONGITUDE,
                        startRoadwayLocation.getString("Longitude"));
                alertData.put(HighwayAlerts.HIGHWAY_ALERT_ROAD_NAME,
                        startRoadwayLocation.getString("RoadName"));
                alertData.put(HighwayAlerts.HIGHWAY_ALERT_LAST_UPDATED, dateFormat
                        .format(new Date(Long.parseLong(item.getString("LastUpdatedTime").substring(6, 19)))));

                alerts.add(alertData);
            }

            // Purge existing highway alerts covered by incoming data
            resolver.delete(HighwayAlerts.CONTENT_URI, null, null);
            // Bulk insert all the new highway alerts
            resolver.bulkInsert(HighwayAlerts.CONTENT_URI, alerts.toArray(new ContentValues[alerts.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 + " LIKE ?",
                    new String[] { "highway_alerts" });

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

From source file:com.android.audiorecorder.ui.ImageViewActvity.java

private void camera() {
    Intent intent = new Intent();
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setAction("com.dahuatech.application.dhcamera.INNER_START_CAMERA");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:com.greatnowhere.radar.MainRadarActivity.java

public void goHome() {
    Intent setIntent = new Intent(Intent.ACTION_MAIN);
    setIntent.addCategory(Intent.CATEGORY_HOME);
    setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(setIntent);/*  w  w w  .ja  v a 2s .c om*/
}

From source file:com.brayanarias.alarmproject.activity.AlarmScreenActivity.java

private void sendNotification(String msg) {
    alarmNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String title = getString(R.string.title_activity_main);
    Intent intent = new Intent(this, AlarmScreenActivity.class);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap();
    NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(title).setSmallIcon(R.drawable.ic_fab_alarm).setLargeIcon(bitmap)
            .setCategory(Notification.CATEGORY_ALARM)
            .setColor(ContextCompat.getColor(getBaseContext(), R.color.colorAccent))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setOngoing(true)
            .setContentIntent(pendingIntent);
    alarmNotificationManager.notify(1503, alarmNotificationBuilder.build());
}