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:com.elkriefy.android.apps.chubbytabby.activity.MainActivity.java

private PendingIntent createPendingEmailIntent() {
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "example@example.com", null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
    return PendingIntent.getActivity(getApplicationContext(), 0, emailIntent, 0);
}

From source file:uk.bowdlerize.service.CensorCensusService.java

@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
    if (null == mNotifyManager)
        mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (null == mBuilder)
        mBuilder = new NotificationCompat.Builder(this);

    if (null == api)
        api = new API(this);

    mContext = this;

    checkedCount = getPreferences(this).getInt("checkedCount", 0);
    censoredCount = getPreferences(this).getInt("censoredCount", 0);
    sendtoORG = getPreferences(this).getBoolean("sendToOrg", false);

    //Make it so tapping an intent will launch the app (Fix #12)
    launchAppIntent = new Intent(mContext, MainActivity.class);
    pendingIntent = PendingIntent.getActivity(mContext, 0, launchAppIntent, 0);
    mBuilder.setContentIntent(pendingIntent);

    //Lets findout why we've been started
    if (intent.getBooleanExtra(API.EXTRA_POLL, false) || intent.getBooleanExtra(API.EXTRA_GCM_TICKLE, false)) {
        prepProbe(intent);/*w w w .  ja v  a  2  s  .c  o m*/
    } else if (intent.hasExtra("url") && !intent.getStringExtra("url").equals("")) {
        performProbe(intent);
    } else {
        onProbeFinish();
    }

    //If we're polling we probably want to stay alive
    if (getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE)
            .getInt(API.SETTINGS_GCM_PREFERENCE, API.SETTINGS_GCM_FULL) == API.SETTINGS_GCM_DISABLED) {
        return START_STICKY;
    } else {
        return START_NOT_STICKY;
    }
}

From source file:android_network.hetnet.vpn_service.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*from   ww w  .  java 2  s.co  m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, MainActivity.class);
        main.putExtra(MainActivity.EXTRA_REFRESH, true);
        main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data)
                .setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.msg_installed, name));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(context.getString(R.string.msg_installed_n));
            else
                expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_key);
    getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT);

    findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
        @Override// w w w.  ja  v  a2  s  . c o  m
        public void onClick(View view) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final String keyType = ((RadioButton) findViewById(R.id.is_key_a)).isChecked()
                    ? ClassicSectorKey.TYPE_KEYA
                    : ClassicSectorKey.TYPE_KEYB;

            new BetterAsyncTask<Void>(AddKeyActivity.this, true, false) {
                @Override
                protected Void doInBackground() throws Exception {
                    ClassicCardKeys keys = ClassicCardKeys.fromDump(keyType, mKeyData);

                    ContentValues values = new ContentValues();
                    values.put(KeysTableColumns.CARD_ID, mTagId);
                    values.put(KeysTableColumns.CARD_TYPE, mCardType);
                    values.put(KeysTableColumns.KEY_DATA, keys.toJSON().toString());

                    getContentResolver().insert(CardKeyProvider.CONTENT_URI, values);

                    return null;
                }

                @Override
                protected void onResult(Void unused) {
                    Intent intent = new Intent(AddKeyActivity.this, KeysActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    finish();
                }
            }.execute();
        }
    });

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Utils.checkNfcEnabled(this, mNfcAdapter);

    Intent intent = getIntent();
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_VIEW)
            && getIntent().getData() != null) {
        try {
            InputStream stream = getContentResolver().openInputStream(getIntent().getData());
            mKeyData = IOUtils.toByteArray(stream);
        } catch (IOException e) {
            Utils.showErrorAndFinish(this, e);
        }
    } else {
        finish();
    }
}

From source file:com.krayzk9s.imgurholo.services.UploadService.java

public void onGetObject(Object o, String tag) {
    String id = (String) o;
    if (id.length() == 7) {
        if (totalUpload != -1)
            ids.add(id);/*from w  ww.ja  v a 2s . c  o m*/
        if (ids.size() == totalUpload) {
            ids.add(0, ""); //weird hack because imgur eats the first item of the array for some bizarre reason
            NewAlbumAsync newAlbumAsync = new NewAlbumAsync("", "", apiCall, ids, this);
            newAlbumAsync.execute();
        }
    } else if (apiCall.settings.getBoolean("AlbumUpload", true)) {
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        Intent viewImageIntent = new Intent();
        viewImageIntent.setAction(Intent.ACTION_VIEW);
        viewImageIntent.setData(Uri.parse("http://imgur.com/a/" + id));
        Intent shareIntent = new Intent();
        shareIntent.setType("text/plain");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        shareIntent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + id);
        PendingIntent viewImagePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                viewImageIntent, 0);
        PendingIntent sharePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                shareIntent, 0);
        Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated)
                .setContentText("Finished Uploading Album").setContentTitle("imgur Image Uploader")
                .setContentIntent(viewImagePendingIntent)
                .addAction(R.drawable.dark_social_share, "Share", sharePendingIntent).build();
        Log.d("Built", "Notification built");
        notificationManager.cancel(0);
        notificationManager.notify(1, notification);
        Log.d("Built", "Notification display");
    } else {
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated)
                .setContentText("Finished Uploading All Images").setContentTitle("imgur Image Uploader")
                .build();
        Log.d("Built", "Notification built");
        notificationManager.cancel(0);
        notificationManager.notify(1, notification);
        Log.d("Built", "Notification display");
    }
}

From source file:app.helloworld.ruichen.nicta.helloworld.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent in = new Intent(this, MainActivity.class);
    if (passExtra != null && passExtra.containsKey("latitude")) {
        in.putExtra("latitude", passExtra.get("latitude").toString());
        in.putExtra("longtitude", passExtra.get("longtitude").toString());
    }/*from   ww w . j a v  a  2s.c o  m*/
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo_nicta_org_nobg)
            .setContentTitle("Evacuation Notification No." + (notificationCounter++))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

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

From source file:com.rocketsingh.biker.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  w  ww  . j  a  v  a 2 s  .  c  om*/
public static void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:jp.co.ipublishing.esnavi.impl.gcm.GcmIntentService.java

/**
 * Notification??/*from w w w .  jav  a  2 s.  co m*/
 *
 * @param alert 
 */
private void sendNotification(@NonNull Alert alert) {
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    final Intent resultIntent = new Intent(this, MapActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent contentIntent = PendingIntent.getActivity(this, 1, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Notification.Builder builder = new Notification.Builder(this).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent)
            .setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
            .setAutoCancel(true).setTicker(alert.getHeadlineBody()).setContentText(alert.getHeadlineBody());

    onPreSendNotification(builder, alert);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationManager.notify(NOTIFICATION_ID, builder.build());
    } else {
        notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
    }
}

From source file:com.ushahidi.android.app.BackgroundService.java

private void showNotification(String tickerText) {

    // This is what should be launched if the user selects our notification.
    Intent baseIntent = new Intent(this, IncidentTab.class);
    baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0);

    // choose the ticker text
    newUshahidiReportNotification = new Notification(R.drawable.notification_icon, tickerText,
            System.currentTimeMillis());
    newUshahidiReportNotification.contentIntent = contentIntent;
    newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL;
    newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent);

    if (Preferences.ringtone) {
        // set the ringer
        Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3"));
        newUshahidiReportNotification.sound = ringURI;
    }//ww w.  j  a v a  2  s  . co m

    if (Preferences.vibrate) {
        double vibrateLength = 100 * Math.exp(0.53 * 20);
        long[] vibrate = new long[] { 100, 100, (long) vibrateLength };
        newUshahidiReportNotification.vibrate = vibrate;

        if (Preferences.flashLed) {
            int color = Color.BLUE;
            newUshahidiReportNotification.ledARGB = color;
        }

        newUshahidiReportNotification.ledOffMS = (int) vibrateLength;
        newUshahidiReportNotification.ledOnMS = (int) vibrateLength;
        newUshahidiReportNotification.flags = newUshahidiReportNotification.flags
                | Notification.FLAG_SHOW_LIGHTS;
    }

    mNotificationManager.notify(Preferences.NOTIFICATION_ID, newUshahidiReportNotification);
}

From source file:com.sonetel.plugins.sonetelcallthru.CallThru.java

@Override
public void onReceive(final Context context, Intent intent) {
    if (SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
        // Retrieve and cache infos from the phone app 
        if (!sPhoneAppInfoLoaded) {
            Resources r = context.getResources();
            BitmapDrawable drawable = (BitmapDrawable) r.getDrawable(R.drawable.ic_wizard_sonetel);
            sPhoneAppBmp = drawable.getBitmap();

            sPhoneAppInfoLoaded = true;/*from  ww w.  j  av  a2  s. c o m*/
        }

        Bundle results = getResultExtras(true);
        //if(pendingIntent != null) {
        //   results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        //}
        results.putString(Intent.EXTRA_TITLE, "Call thru");// context.getResources().getString(R.string.use_pstn));
        if (sPhoneAppBmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
        }
        if (intent.getStringExtra(Intent.EXTRA_TEXT) == null)
            return;

        //final PendingIntent pendingIntent = null;
        final String callthrunum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        final String dialledNum = intent.getStringExtra(Intent.EXTRA_TEXT);
        // We must handle that clean way cause when call just to 
        // get the row in account list expect this to reply correctly
        if (callthrunum != null && PhoneCapabilityTester.isPhone(context)) {

            if (!callthrunum.equalsIgnoreCase("")) {
                DBAdapter dbAdapt = new DBAdapter(context);

                // Build pending intent

                SipAccount = dbAdapt.getAccount(1);

                if (SipAccount != null) {

                    Intent i = new Intent(Intent.ACTION_CALL);
                    i.setData(Uri.fromParts("tel", callthrunum, null));
                    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i,
                            PendingIntent.FLAG_CANCEL_CURRENT);

                    NetWorkThread = new Thread() {
                        public void run() {
                            SendMsgToNetWork(dialledNum, context, pendingIntent);
                        };
                    };

                    NetWorkThread.start();

                }

                if (!dialledNum.equalsIgnoreCase("")) {
                    SipCallSessionImpl callInfo = new SipCallSessionImpl();

                    callInfo.setRemoteContact(dialledNum);
                    callInfo.setIncoming(false);
                    callInfo.callStart = System.currentTimeMillis();
                    callInfo.setAccId(3);
                    //callInfo.setLastStatusCode(pjsua.PJ_SUCCESS);

                    ContentValues cv = CallLogHelper.logValuesForCall(context, callInfo, callInfo.callStart);
                    context.getContentResolver().insert(SipManager.CALLLOG_URI, cv);

                }
            } else {
                Location_Finder LocFinder = new Location_Finder(context);
                if (LocFinder.getContryName().startsWith("your"))
                    Toast.makeText(context,
                            "Country of your current location unknown. Call thru not available.",
                            Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(context,
                            "No Call thru access number available in " + LocFinder.getContryName(),
                            Toast.LENGTH_LONG).show();
                //Toast.makeText(context, "No Call thru access number available in ", Toast.LENGTH_LONG).show();
            }
        }

        // This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
        results.putString(Intent.EXTRA_PHONE_NUMBER, callthrunum);

    }

}