Search in sources :

Example 96 with PendingIntent

use of android.app.PendingIntent in project Klyph by jonathangerbaud.

the class KlyphNotification method sendNotification.

public static void sendNotification(Context context, Builder builder, Notification notification) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    Intent resultIntent = null;
    final String id = notification.getObject_id();
    final String name = notification.getObject_name();
    final String type = notification.getObject_type();
    if (type.equals(Notification.TYPE_FRIEND) || type.equals(Notification.TYPE_POKE) || type.equals(Notification.TYPE_USER)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, Notification.TYPE_FRIEND);
        stackBuilder.addParentStack(UserActivity.class);
    } else if (type.equals(Notification.TYPE_EVENT)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, type);
        stackBuilder.addParentStack(EventActivity.class);
    } else if (type.equals(Notification.TYPE_PAGE)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, type);
        stackBuilder.addParentStack(PageActivity.class);
    } else if (type.equals(Notification.TYPE_GROUP)) {
        if (notification.getGroup().getGid().length() == 0) {
            // That is not a group but a post in a group
            resultIntent = new Intent(context, StreamActivity.class);
            resultIntent.putExtra(KlyphBundleExtras.STREAM_GROUP, true);
            resultIntent.putExtra(KlyphBundleExtras.STREAM_ID, id);
            stackBuilder.addParentStack(StreamActivity.class);
        } else {
            resultIntent = Klyph.getIntentForParams(context, id, name, type);
            stackBuilder.addParentStack(GroupActivity.class);
        }
    } else if (type.equals(Notification.TYPE_PHOTO)) {
        resultIntent = new Intent(context, ImageActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.PHOTO_ID, id);
        stackBuilder.addParentStack(ImageActivity.class);
    } else if (type.equals(Notification.TYPE_ALBUM)) {
        resultIntent = new Intent(context, AlbumPhotosActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.ALBUM_ID, id);
        resultIntent.putExtra(KlyphBundleExtras.ALBUM_NAME, name);
    } else if (type.equals(Notification.TYPE_APP_REQUEST)) {
        resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notification.getHref()));
    } else if (type.equals(Notification.TYPE_VIDEO)) {
        resultIntent = new Intent(context, MainActivity.class);
    // ???
    // resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notification.getHref()));
    } else {
        // Stream
        resultIntent = new Intent(context, StreamActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.STREAM_ID, id);
        stackBuilder.addParentStack(StreamActivity.class);
    }
    resultIntent.putExtra(KlyphBundleExtras.SET_NOTIFICATION_AS_READ, true);
    resultIntent.putExtra(KlyphBundleExtras.NOTIFICATION_ID, notification.getNotification_id());
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntentWithParentStack(resultIntent);
    int intentCode = (int) Math.round(Math.random() * 1000000);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(intentCode, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    Intent intent = new Intent(context, NotificationDeletedReceiver.class);
    intent.putExtra(KlyphBundleExtras.NOTIFICATION_ID, notification.getNotification_id());
    int random = (int) Math.round(Math.random() * 100000);
    builder.setDeleteIntent(PendingIntent.getBroadcast(context.getApplicationContext(), random, intent, 0));
    final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Log.d("NotificationService", "Notify " + notification.getNotification_id());
    final String tag = context.getPackageName() + "_" + notification.getNotification_id();
    // pair (tag, id) must be unique
    // because notificationId may not be converted to an int
    // tag is the unique key
    mNotificationManager.notify(tag, 0, builder.build());
}
Also used : ImageActivity(com.abewy.android.apps.klyph.app.ImageActivity) NotificationManager(android.app.NotificationManager) StreamActivity(com.abewy.android.apps.klyph.app.StreamActivity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) EventActivity(com.abewy.android.apps.klyph.app.EventActivity) GroupActivity(com.abewy.android.apps.klyph.app.GroupActivity)

Example 97 with PendingIntent

use of android.app.PendingIntent in project android-simpl3r by jgilfelt.

the class UploadService method buildNotification.

private Notification buildNotification(String msg, int progress) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setWhen(System.currentTimeMillis());
    builder.setTicker(msg);
    builder.setContentTitle(getString(R.string.app_name));
    builder.setContentText(msg);
    builder.setSmallIcon(R.drawable.ic_stat_uploading);
    builder.setOngoing(true);
    builder.setProgress(100, progress, false);
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    builder.setContentIntent(contentIntent);
    return builder.build();
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 98 with PendingIntent

use of android.app.PendingIntent in project SmartAndroidSource by jaychou2012.

the class SearchView method createVoiceAppSearchIntent.

/**
	 * Create and return an Intent that can launch the voice search activity,
	 * perform a specific voice transcription, and forward the results to the
	 * searchable activity.
	 * 
	 * @param baseIntent
	 *            The voice app search intent to start from
	 * @return A completely-configured intent ready to send to the voice search
	 *         activity
	 */
private Intent createVoiceAppSearchIntent(Intent baseIntent, SearchableInfo searchable) {
    ComponentName searchActivity = searchable.getSearchActivity();
    // create the necessary intent to set up a search-and-forward operation
    // in the voice search system. We have to keep the bundle separate,
    // because it becomes immutable once it enters the PendingIntent
    Intent queryIntent = new Intent(Intent.ACTION_SEARCH);
    queryIntent.setComponent(searchActivity);
    PendingIntent pending = PendingIntent.getActivity(getContext(), 0, queryIntent, PendingIntent.FLAG_ONE_SHOT);
    // Now set up the bundle that will be inserted into the pending intent
    // when it's time to do the search. We always build it here (even if
    // empty)
    // because the voice search activity will always need to insert "QUERY"
    // into
    // it anyway.
    Bundle queryExtras = new Bundle();
    // Now build the intent to launch the voice search. Add all necessary
    // extras to launch the voice recognizer, and then all the necessary
    // extras
    // to forward the results to the searchable activity
    Intent voiceIntent = new Intent(baseIntent);
    // Add all of the configuration options supplied by the searchable's
    // metadata
    String languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM;
    String prompt = null;
    String language = null;
    int maxResults = 1;
    Resources resources = getResources();
    if (searchable.getVoiceLanguageModeId() != 0) {
        languageModel = resources.getString(searchable.getVoiceLanguageModeId());
    }
    if (searchable.getVoicePromptTextId() != 0) {
        prompt = resources.getString(searchable.getVoicePromptTextId());
    }
    if (searchable.getVoiceLanguageId() != 0) {
        language = resources.getString(searchable.getVoiceLanguageId());
    }
    if (searchable.getVoiceMaxResults() != 0) {
        maxResults = searchable.getVoiceMaxResults();
    }
    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity == null ? null : searchActivity.flattenToShortString());
    // Add the values that configure forwarding the results
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pending);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, queryExtras);
    return voiceIntent;
}
Also used : Bundle(android.os.Bundle) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) PendingIntent(android.app.PendingIntent) SuggestionsAdapter.getColumnString(com.smartandroid.sa.sherlock.widget.SuggestionsAdapter.getColumnString) Resources(android.content.res.Resources)

Example 99 with PendingIntent

use of android.app.PendingIntent in project Talon-for-Twitter by klinker24.

the class PhotoFragment method saveImage.

public void saveImage() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            Looper.prepare();
            try {
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity).setSmallIcon(R.drawable.ic_stat_icon).setTicker(getResources().getString(R.string.downloading) + "...").setContentTitle(getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.saving_picture) + "...").setProgress(100, 100, true).setLargeIcon(BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_action_save));
                NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
                mNotificationManager.notify(6, mBuilder.build());
                URL mUrl = new URL(url);
                HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
                InputStream is = new BufferedInputStream(conn.getInputStream());
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = false;
                Bitmap bitmap = decodeSampledBitmapFromResourceMemOpt(is, 600, 600);
                Random generator = new Random();
                int n = 1000000;
                n = generator.nextInt(n);
                String fname = "Image-" + n;
                Uri uri = IOUtils.saveImage(bitmap, fname, activity);
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setDataAndType(uri, "image/*");
                PendingIntent pending = PendingIntent.getActivity(activity, 91, intent, 0);
                mBuilder = new NotificationCompat.Builder(activity).setContentIntent(pending).setSmallIcon(R.drawable.ic_stat_icon).setTicker(getResources().getString(R.string.saved_picture) + "...").setContentTitle(getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.saved_picture) + "!").setLargeIcon(BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_action_save));
                mNotificationManager.notify(6, mBuilder.build());
            } catch (Exception e) {
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity).setSmallIcon(R.drawable.ic_stat_icon).setTicker(getResources().getString(R.string.error) + "...").setContentTitle(getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.error) + "...").setProgress(100, 100, true).setLargeIcon(BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_action_save));
                NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
                mNotificationManager.notify(6, mBuilder.build());
            }
        }
    }).start();
}
Also used : NotificationManager(android.app.NotificationManager) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri) URL(java.net.URL) Bitmap(android.graphics.Bitmap) HttpURLConnection(java.net.HttpURLConnection) Random(java.util.Random) BufferedInputStream(java.io.BufferedInputStream) NotificationCompat(android.support.v4.app.NotificationCompat) BitmapFactory(android.graphics.BitmapFactory) PendingIntent(android.app.PendingIntent)

Example 100 with PendingIntent

use of android.app.PendingIntent in project Talon-for-Twitter by klinker24.

the class HomeFragment method doRefresh.

public int doRefresh() {
    int numberNew = 0;
    if (TimelineRefreshService.isRunning || WidgetRefreshService.isRunning || CatchupPull.isRunning) {
        // quit if it is running in the background
        return 0;
    }
    try {
        Cursor cursor = cursorAdapter.getCursor();
        if (cursor.moveToLast()) {
            long id = cursor.getLong(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID));
            sharedPrefs.edit().putLong("current_position_" + currentAccount, id).commit();
            HomeDataSource.getInstance(context).markPosition(currentAccount, id);
        //HomeContentProvider.updateCurrent(currentAccount, context, id);
        }
    } catch (Exception e) {
    }
    boolean needClose = false;
    context.sendBroadcast(new Intent("com.klinker.android.twitter.CLEAR_PULL_UNREAD"));
    twitter = Utils.getTwitter(context, settings);
    final List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>();
    boolean foundStatus = false;
    Paging paging = new Paging(1, 200);
    long[] lastId = null;
    long id;
    try {
        lastId = HomeDataSource.getInstance(context).getLastIds(currentAccount);
        id = lastId[1];
    } catch (Exception e) {
        id = sharedPrefs.getLong("account_" + currentAccount + "_lastid", 1l);
    }
    Log.v("talon_inserting", "since_id=" + id);
    try {
        paging.setSinceId(id);
    } catch (Exception e) {
    // 0 for some reason, so dont set one and let the database sort which should show and which shouldn't
    }
    long beforeDownload = Calendar.getInstance().getTimeInMillis();
    for (int i = 0; i < settings.maxTweetsRefresh; i++) {
        try {
            if (!foundStatus) {
                paging.setPage(i + 1);
                List<Status> list = twitter.getHomeTimeline(paging);
                statuses.addAll(list);
                if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) {
                    Log.v("talon_inserting", "found status");
                    foundStatus = true;
                } else {
                    Log.v("talon_inserting", "haven't found status");
                    foundStatus = false;
                }
            }
        } catch (TwitterException e) {
            Log.v("talon_error", "code: " + e.getErrorCode());
            if (e.getErrorCode() == 88) {
                // rate limit reached
                rateLimited = true;
                foundStatus = true;
                return 0;
            }
        } catch (Exception e) {
            // the page doesn't exist
            e.printStackTrace();
            Log.v("talon_error", "error with refresh");
            foundStatus = true;
        } catch (OutOfMemoryError o) {
        // don't know why...
        }
    }
    long afterDownload = Calendar.getInstance().getTimeInMillis();
    Log.v("talon_inserting", "downloaded " + statuses.size() + " tweets in " + (afterDownload - beforeDownload));
    if (statuses.size() > 0) {
        statuses.remove(statuses.size() - 1);
    }
    HashSet hs = new HashSet();
    hs.addAll(statuses);
    statuses.clear();
    statuses.addAll(hs);
    Log.v("talon_inserting", "tweets after hashset: " + statuses.size());
    manualRefresh = false;
    if (needClose) {
        HomeDataSource.dataSource = null;
        Log.v("talon_home_frag", "sending the reset home broadcase in needclose section");
        dontGetCursor = true;
        context.sendBroadcast(new Intent("com.klinker.android.twitter.RESET_HOME"));
    }
    if (lastId == null) {
        try {
            lastId = HomeDataSource.getInstance(context).getLastIds(currentAccount);
        } catch (Exception e) {
            // let the
            lastId = new long[] { 0, 0, 0, 0, 0 };
        }
    }
    try {
        numberNew = insertTweets(statuses, lastId);
    } catch (NullPointerException e) {
        return 0;
    }
    if (numberNew > statuses.size()) {
        numberNew = statuses.size();
    }
    if (numberNew > 0 && statuses.size() > 0) {
        sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit();
    }
    Log.v("talon_inserting", "inserted " + numberNew + " tweets in " + (Calendar.getInstance().getTimeInMillis() - afterDownload));
    //numberNew = statuses.size();
    unread = numberNew;
    statuses.clear();
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    long now = new Date().getTime();
    long alarm = now + settings.timelineRefresh;
    PendingIntent pendingIntent = PendingIntent.getService(context, HOME_REFRESH_ID, new Intent(context, TimelineRefreshService.class), 0);
    if (settings.timelineRefresh != 0)
        am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.timelineRefresh, pendingIntent);
    else
        am.cancel(pendingIntent);
    int unreadCount;
    try {
        unreadCount = HomeDataSource.getInstance(context).getUnreadCount(currentAccount);
    } catch (Exception e) {
        unreadCount = numberNew;
    }
    return unreadCount;
}
Also used : Status(twitter4j.Status) TimelineRefreshService(com.klinker.android.twitter.services.TimelineRefreshService) Paging(twitter4j.Paging) ArrayList(java.util.ArrayList) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Cursor(android.database.Cursor) TwitterException(twitter4j.TwitterException) StaleDataException(android.database.StaleDataException) Date(java.util.Date) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) TwitterException(twitter4j.TwitterException) HashSet(java.util.HashSet)

Aggregations

PendingIntent (android.app.PendingIntent)1208 Intent (android.content.Intent)1010 Notification (android.app.Notification)222 NotificationCompat (android.support.v4.app.NotificationCompat)167 AlarmManager (android.app.AlarmManager)149 NotificationManager (android.app.NotificationManager)148 Bundle (android.os.Bundle)75 RemoteViews (android.widget.RemoteViews)67 RemoteException (android.os.RemoteException)64 Resources (android.content.res.Resources)62 Bitmap (android.graphics.Bitmap)61 Context (android.content.Context)60 ComponentName (android.content.ComponentName)55 Test (org.junit.Test)44 Uri (android.net.Uri)42 IntentFilter (android.content.IntentFilter)41 SharedPreferences (android.content.SharedPreferences)36 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)33 UserHandle (android.os.UserHandle)31 ArrayList (java.util.ArrayList)30