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:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToGroupObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    try {//  ww  w .j  ava 2 s . c o m
        String groupName = obj.getString(GROUP_NAME);
        Uri dynUpdateUri = Uri.parse(obj.getString(DYN_UPDATE_URI));

        Intent launch = new Intent(Intent.ACTION_VIEW);
        launch.setData(dynUpdateUri);
        launch.putExtra("type", TYPE);
        launch.putExtra("creator", false);
        launch.putExtra(SENDER, from.id);
        launch.putExtra(GROUP_NAME, groupName);
        launch.putExtra(DYN_UPDATE_URI, dynUpdateUri);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
                PendingIntent.FLAG_CANCEL_CURRENT);

        (new PresenceAwareNotify(context)).notify("Invitation from " + from.name,
                "Invitation from " + from.name, "Join the group '" + groupName + "'.", contentIntent);

    } catch (JSONException e) {
        Log.e(TAG, "Error handling message: ", e);
    }
}

From source file:be.uhasselt.privacypolice.NotificationHandler.java

/**
 * Asks the user whether it is certain that a network should be currently available
 * @param SSID The name of the network//from  w ww . j a va2  s. co m
 * @param BSSID The MAC address of the access point that triggered this (only used when we will block the AP)
 */
public void askNetworkPermission(String SSID, String BSSID) {
    Log.d("PrivacyPolice", "Asking permission for " + SSID + " (" + BSSID + ")");
    // Intent that will be used when the user allows the network
    Intent addIntent = new Intent(ctx, PermissionChangeReceiver.class);
    addIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID).putExtra("enable", true);
    PendingIntent addPendingIntent = PendingIntent.getBroadcast(ctx, 0, addIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Intent that will be used when the user blocks the network
    Intent disableIntent = new Intent(ctx, PermissionChangeReceiver.class);
    disableIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID).putExtra("enable", false);
    PendingIntent disablePendingIntent = PendingIntent.getBroadcast(ctx, 1, disableIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Intent that will be used when the user's OS does not support notification actions
    Intent activityIntent = new Intent(ctx, AskPermissionActivity.class);
    activityIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID);
    PendingIntent activityPendingIntent = PendingIntent.getActivity(ctx, 2, activityIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    // Build the notification dynamically, based on the network name
    Resources res = ctx.getResources();
    String headerString = String.format(res.getString(R.string.permission_header), SSID);
    String permissionString = String.format(res.getString(R.string.ask_permission), SSID);
    String yes = res.getString(R.string.yes);
    String no = res.getString(R.string.no);

    // NotificationCompat makes sure that the notification will also work on Android <4.0
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_notification).setPriority(Notification.PRIORITY_MAX) // To force it to be first in list (and thus, expand)
            .setContentTitle(headerString).setContentText(permissionString)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(permissionString))
            .setContentIntent(activityPendingIntent)
            .addAction(android.R.drawable.ic_delete, no, disablePendingIntent)
            .addAction(android.R.drawable.ic_input_add, yes, addPendingIntent);
    notificationManager.notify(0, mBuilder.build());
}

From source file:li.klass.fhem.appwidget.view.widget.medium.TargetStateWidgetView.java

@Override
protected void fillWidgetView(Context context, RemoteViews view, FhemDevice<?> device,
        WidgetConfiguration widgetConfiguration) {
    String payload = widgetConfiguration.payload.get(1);
    String state = device.getEventMapStateFor(payload);

    view.setTextViewText(R.id.button, state);

    PendingIntent pendingIntent;//from   w w  w. j a v a 2s.  c  o  m
    if (requiresAdditionalInformation(state)) {
        Intent actionIntent = new Intent(context, TargetStateAdditionalInformationActivity.class);
        actionIntent.putExtra(BundleExtraKeys.DEVICE_NAME, device.getName());
        actionIntent.putExtra(BundleExtraKeys.DEVICE_TARGET_STATE, payload);
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        pendingIntent = PendingIntent.getActivity(context, widgetConfiguration.widgetId, actionIntent,
                FLAG_UPDATE_CURRENT);
    } else {
        Intent actionIntent = new Intent(Actions.DEVICE_SET_STATE);
        actionIntent.setClass(context, DeviceIntentService.class);
        actionIntent.putExtra(BundleExtraKeys.DEVICE_NAME, device.getName());
        actionIntent.putExtra(BundleExtraKeys.DEVICE_TARGET_STATE, payload);

        pendingIntent = PendingIntent.getService(context, widgetConfiguration.widgetId, actionIntent,
                FLAG_UPDATE_CURRENT);
    }

    view.setOnClickPendingIntent(R.id.button, pendingIntent);

    openDeviceDetailPageWhenClicking(R.id.main, view, device, widgetConfiguration, context);
}

From source file:app.com.ark.android.sunshine.GcmBroadcastReceiver.java

private void sendNotification(Context context, String msg) {
    mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class),
            0);/*w w w . ja  v a 2 s . c  o  m*/

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.art_storm).setContentTitle("Weather Alert!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.versul.newbornswatcher.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w  ww. j a  v  a 2s. 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 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.eye);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.ic_dialog_alert)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_large))
            .setContentTitle("Newborns Watcher").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:azzaoui.sociadee.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w w w .  j  a v  a 2 s . c om
 */
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.pp_swag).setContentTitle("GCM Message").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.easyauth.EasyAuth.GCMIntentService.java

private void sendNotification(Bundle extras) {

    String type = extras.getString("type");
    if (type.equals(Constants.EASYAUTH_LOGIN)) {
        String token = extras.getString("token");
        String username = extras.getString("username");

        if (token.isEmpty()) {
            Log.e(TAG, "Empty token received");
        }/*w  w w  .jav  a  2  s . c  o  m*/
        if (username.isEmpty()) {
            Log.e(TAG, "Empty username received");
        }

        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class),
                0);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher).setContentTitle("EasyAuth Notification")
                .setStyle(new NotificationCompat.BigTextStyle().bigText("EasyAuth Login Performed"))
                .setContentText("EasyAuth Login Performed by " + username);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

        JSONObject json = new JSONObject();
        try {
            json.put("token", token);
            json.put("username", username);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        new AsyncHttpTask(this.getApplicationContext()).execute("ip", json.toString());
    } else if (type.equals(Constants.EASYAUTH_TOTP_SECRET)) {
        String username = extras.getString("username");
        String secret = extras.getString("secret");

        if (secret.isEmpty()) {
            Log.e(TAG, "Empty secret received");
        }
        if (username.isEmpty()) {
            Log.e(TAG, "Empty username received");
        }

        SharedPreferences prefs = getSharedPreferences(Constants.EASYAUTH_PREFERENCES_KEY,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(Constants.EASYAUTH_TOTP_SECRET_KEY, secret);
        editor.putString(Constants.EASYAUTH_USERNAME_KEY, username);
        editor.commit();
    }
}

From source file:org.openplans.rcavl.LocationService.java

public void realStart(Intent intent) {
    String url = intent.getStringExtra("pingUrl");
    String email = intent.getStringExtra("email");
    String password = intent.getStringExtra("password");
    pingInterval = intent.getIntExtra("pingInterval", 60);

    Notification notification = new Notification(R.drawable.icon, "Ridepilot Mobile",
            System.currentTimeMillis());
    Intent appIntent = new Intent(this, RCAVL.class);

    appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, appIntent, 0);

    notification.setLatestEventInfo(this, "Ridepilot Mobile", "connected", pi);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(66786, notification);

    thread = new LocationServiceThread(url, email, password);
    new Thread(thread).start();
}

From source file:com.codebutler.farebot.activities.MainActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);

    mDataCache = new HashMap<String, TransitIdentity>();

    registerForContextMenu(getListView());

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Intent intent = new Intent(this, ReadingTagActivity.class);
    intent.addFlags(/*from w  w  w  . ja  v a2 s.  c o m*/
            Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    mTechLists = new String[][] { new String[] { IsoDep.class.getName() },
            new String[] { MifareClassic.class.getName() }, new String[] { MifareUltralight.class.getName() },
            new String[] { NfcF.class.getName() } };

    setListAdapter(new CardsAdapter());
    getLoaderManager().initLoader(0, null, this);
}

From source file:de.wikilab.android.friendica01.FileUploadService.java

private void showFailMsg(Context ctx, String txt) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Log.e("Andfrnd/UploadFile", "Upload FAILED: " + txt);

    //Instantiate the Notification:
    CharSequence tickerText = "Upload failed, please retry!";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    CharSequence contentTitle = "Upload failed, click to retry!";
    CharSequence contentText = txt;
    Intent notificationIntent = new Intent(this, FriendicaImgUploadActivity.class);
    Bundle b = new Bundle();
    b.putParcelable(Intent.EXTRA_STREAM, fileToUpload);
    b.putString(Intent.EXTRA_SUBJECT, subject);
    b.putString(EXTRA_DESCTEXT, descText);

    notificationIntent.putExtras(b);/*  w  ww .j  ava  2s .c  o m*/
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_FAILED_ID, notification);
    //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show();
}