Example usage for android.app PendingIntent getActivity

List of usage examples for android.app PendingIntent getActivity

Introduction

In this page you can find the example usage for android.app PendingIntent getActivity.

Prototype

public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags) 

Source Link

Document

Retrieve a PendingIntent that will start a new activity, like calling Context#startActivity(Intent) Context.startActivity(Intent) .

Usage

From source file:at.wada811.utils.IntentUtils.java

/**
 * Viewer???PendingIntent??/*w w  w . j  a v a2s  . c o  m*/
 *
 * @param context
 * @param filePath
 * @param mimeType
 * @return pendingIntent
 */
public static PendingIntent createFileViewPendingIntent(Context context, String filePath) {
    int requestCode = 0; // Private request code for the sender (currently not used).
    Intent intent = IntentUtils.createFileViewIntent(filePath);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    return pendingIntent;
}

From source file:org.ametro.util.WebUtil.java

public static void downloadFileAsync(final Context appContext, final File path, final URI uri,
        final File temp) {

    final DownloadContext context = new DownloadContext();
    context.Path = path;/*from  w  w w  .ja v  a 2s. co  m*/
    context.IsCanceled = false;
    context.IsUnpackFinished = false;
    context.IsFailed = false;

    final NotificationManager notificationManager = (NotificationManager) appContext
            .getSystemService(Context.NOTIFICATION_SERVICE);

    final Handler handler = new Handler();

    final Runnable updateProgress = new Runnable() {
        public void run() {
            if (context.Notification == null) {
                context.Notification = new Notification(android.R.drawable.stat_sys_download,
                        "Downloading icons", System.currentTimeMillis());
                context.Notification.flags = Notification.FLAG_NO_CLEAR;
                Intent notificationIntent = new Intent();
                context.ContentIntent = PendingIntent.getActivity(appContext, 0, notificationIntent, 0);
            }
            if (context.IsFailed) {
                notificationManager.cancelAll();
                context.Notification = new Notification(android.R.drawable.stat_sys_warning,
                        "Icons download failed", System.currentTimeMillis());
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded failed",
                        context.ContentIntent);
                notificationManager.notify(2, context.Notification);

            } else if (context.IsUnpackFinished) {
                notificationManager.cancelAll();
                context.Notification = new Notification(android.R.drawable.stat_sys_download_done,
                        "Icons unpacked", System.currentTimeMillis());
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded and unpacked.",
                        context.ContentIntent);
                notificationManager.notify(3, context.Notification);

            } else if (context.Position == 0 && context.Total == 0) {
                context.Notification.setLatestEventInfo(appContext, "aMetro",
                        "Download icons: connecting server", context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            } else if (context.Position < context.Total) {
                context.Notification.setLatestEventInfo(appContext, "aMetro",
                        "Download icons: " + context.Position + "/" + context.Total, context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            } else {
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons unpacking",
                        context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            }
        }
    };

    final Thread async = new Thread() {
        public void run() {
            WebUtil.downloadFile(context, uri, temp, false, new IDownloadListener() {

                public void onBegin(Object context, File file) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.Total = 0;
                    downloadContext.Position = 0;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public boolean onUpdate(Object context, long position, long total) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.Total = total;
                    downloadContext.Position = position;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                    return !downloadContext.IsCanceled;
                }

                public void onDone(Object context, File file) throws Exception {
                    DownloadContext downloadContext = (DownloadContext) context;
                    File path = downloadContext.Path;
                    ZipUtil.unzip(file, path);
                    downloadContext.IsUnpackFinished = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public void onCanceled(Object context, File file) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.IsCanceled = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public void onFailed(Object context, File file, Throwable reason) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.IsFailed = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

            });
        };
    };
    async.start();
}

From source file:barqsoft.footballscores.widget.WidgetListProvider.java

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_list);

        // Create an Intent to launch MainActivity
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        views.setOnClickPendingIntent(R.id.widget_item, pendingIntent);

        // Set up the collection
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            setRemoteAdapter(context, views);
        } else {/*  ww w .  ja  v  a2s .co m*/
            setRemoteAdapterV11(context, views);
        }
        Intent clickIntentTemplate = new Intent(context, MainActivity.class);
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
        views.setEmptyView(R.id.widget_list, R.id.widget_empty);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

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

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.setComponent(new ComponentName(context.getPackageName(), HomeActivity.class.getName()));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);
    String msg = obj.optString(TEXT);
    (new PresenceAwareNotify(context)).notify("IM from " + from.name, "IM from " + from.name, "\"" + msg + "\"",
            contentIntent);//from   w  w  w.  ja  v a2s  . co m
}

From source file:be.thomasave.executeorder42.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from w  ww. java 2 s  .c o m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon).setContentTitle("Execute Order 42").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.manning.androidhacks.hack046.helper.NotificationHelper.java

private static PendingIntent getPendingIntent(Context ctx) {
    Intent intent = new Intent(ctx, MsgActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return PendingIntent.getActivity(ctx, 0, intent, 0);
}

From source file:com.networkmanagerapp.JSONBackgroundDownloaderService.java

/**
 * Displays a notification in the system notification area
 *//*from  w w  w  .  j av  a2  s .c  o  m*/
private void showNotification() {
    CharSequence text = getText(R.string.download_service_started);
    Notification notification = new Notification(R.drawable.ic_stat_networkman, text,
            System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, NetworkManagerMainActivity.class), 0);
    notification.setLatestEventInfo(this, text, text, contentIntent);
    mNM.notify(R.string.download_service_started, notification);
}

From source file:assistance.shopping.msc.assistant.support.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message shoppingBroadcastDescription received.
 *///from ww  w  . j  a v a2 s . co m
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, LoginActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("FCM Message")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java

static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    WidgetPreferences preferences = MtGoxPreferencesActivity.getWidgetPreferences(context, appWidgetId);

    if (preferences == null) {
        // Don't do anything unless the rate service has been chosen.
        // Show a "please remove this widget and add a new one"
        appWidgetManager.updateAppWidget(appWidgetId,
                new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me));
        return;/*from w  ww.j  av a  2s.  c o  m*/
    }

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
    Intent clickIntent = new Intent(context, GraphPopupActivity.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call
    // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE
    //       cached intent will be used for all widget instances!
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
    views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent);
    views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName());

    MtGoxDataOpenHelper dbHelper = new MtGoxDataOpenHelper(context);
    MtGoxTickerData prevData = dbHelper.getLastTickerData(preferences);

    MtGoxTickerData newData;
    JSONObject latestQuoteJSON = getLatestQuoteJSON(preferences);
    if (latestQuoteJSON != null) {
        newData = preferences.getRateService().parseJSON(latestQuoteJSON);
        newData.setCurrencyConversion(preferences.getCurrencyConversion());
        storeLastValueIfNotNull(dbHelper, newData);
        updateViews(views, prevData, newData, preferences);
    } else if (prevData != null) {
        newData = prevData;
        updateViews(views, prevData, newData, preferences);
    } else {
        updateViewsWithError(views, preferences);
    }
    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:jp.co.brilliantservice.android.writertdtext.HomeActivity.java

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

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
        Toast.makeText(getApplicationContext(), "not found NFC feature", Toast.LENGTH_SHORT).show();
        finish();/*from w ww.  j  ava  2 s.c  o m*/
        return;
    }

    if (!mNfcAdapter.isEnabled()) {
        Toast.makeText(getApplicationContext(), "NFC feature is not available", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()), 0);
    IntentFilter[] intentFilter = new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED), };
    String[][] techList = new String[][] { { android.nfc.tech.NdefFormatable.class.getName() },
            { android.nfc.tech.Ndef.class.getName() } };
    mNfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilter, techList);

}