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:ru.orangesoftware.financisto2.export.flowzr.FlowzrSyncEngine.java

public static void builAndRun(Context context) {
    final FlowzrSyncActivity fa = FlowzrSyncActivity.getMySelf();
    if (fa == null) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        Builder mNotifyBuilder = new NotificationCompat.Builder(context);
        mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle(context.getString(R.string.flowzr_sync))
                .setContentText(context.getString(R.string.flowzr_sync_require_tap));
        nm.notify(SYNC_NOTIFICATION_ID, mNotifyBuilder.build());
        Log.e(TAG, "Sync unactive: the required activity is missing.");
        return;//  w  ww  . j a v a  2s .com
    } else {
        if (FlowzrSyncActivity.isRunning) {
            Log.i(TAG, "Sync already in progress");
        } else {
            if ((System.currentTimeMillis() - FlowzrSyncOptions.last_sync_ts) > 30 * 1000) {
                Log.i(TAG, "Starting Auto-Sync Task");
                fa.runOnUiThread(new Runnable() {
                    public void run() {
                        fa.setRunning();
                    }
                });
                fa.initProgressDialog();
                new FlowzrSyncEngine(fa);
            } else {
                Log.i(TAG, "Sync have just been done");
            }
        }
    }
}

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

private Notification getEnforcingNotification(int allowed, int blocked, int hosts) {
    Intent main = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setContentTitle(getString(R.string.msg_started));
    else/*  w  ww .ja v a2 s .  c o m*/
        builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.msg_started));

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

    if (allowed > 0 || blocked > 0 || hosts > 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            if (Util.isPlayStoreInstall(this))
                builder.setContentText(getString(R.string.msg_packages, allowed, blocked));
            else
                builder.setContentText(getString(R.string.msg_hosts, allowed, blocked, hosts));
            return builder.build();
        } else {
            NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
            notification.bigText(getString(R.string.msg_started));
            if (Util.isPlayStoreInstall(this))
                notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
            else
                notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts));
            return notification.build();
        }
    } else
        return builder.build();
}

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

private Notification getWaitingNotification() {
    Intent main = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setContentTitle(getString(R.string.msg_waiting));
    else/*from www  . j ava2s .c  o m*/
        builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.msg_waiting));

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

    return builder.build();
}

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

private void showDisabledNotification() {
    Intent main = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }//from w w w. j  a va  2  s . c  o  m

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_revoked));

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

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

private void showAutoStartNotification() {
    Intent main = new Intent(this, MainActivity.class);
    main.putExtra(MainActivity.EXTRA_APPROVE, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_autostart)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }//from www . ja va 2 s . c  om

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_autostart));

    NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build());
}

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

private void showErrorNotification(String message) {
    Intent main = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_error, message)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }/*  w  ww  .j  av  a 2s .c  om*/

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_error, message));
    notification.setSummaryText(message);

    NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build());
}

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

private void showAccessNotification(int uid) {
    String name = TextUtils.join(", ", Util.getApplicationNames(uid, ServiceSinkhole.this));

    Intent main = new Intent(ServiceSinkhole.this, MainActivity.class);
    main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid));
    PendingIntent pi = PendingIntent.getActivity(ServiceSinkhole.this, uid + 10000, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    int colorOn = tv.data;
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    int colorOff = tv.data;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_cloud_upload_white_24dp).setGroup("AccessAttempt").setContentIntent(pi)
            .setColor(colorOff).setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setContentTitle(name).setContentText(getString(R.string.msg_access_n));
    else/*w  w  w . j  a  v  a 2s .c o m*/
        builder.setContentTitle(getString(R.string.app_name))
                .setContentText(getString(R.string.msg_access, name));

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

    DateFormat df = new SimpleDateFormat("dd HH:mm");

    NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        notification.addLine(getString(R.string.msg_access_n));
    else {
        String sname = getString(R.string.msg_access, name);
        int pos = sname.indexOf(name);
        Spannable sp = new SpannableString(sname);
        sp.setSpan(new StyleSpan(Typeface.BOLD), pos, pos + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        notification.addLine(sp);
    }

    Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getAccessUnset(uid, 7);
    int colDAddr = cursor.getColumnIndex("daddr");
    int colTime = cursor.getColumnIndex("time");
    int colAllowed = cursor.getColumnIndex("allowed");
    while (cursor.moveToNext()) {
        StringBuilder sb = new StringBuilder();
        sb.append(df.format(cursor.getLong(colTime))).append(' ');

        String daddr = cursor.getString(colDAddr);
        if (Util.isNumericAddress(daddr))
            try {
                daddr = InetAddress.getByName(daddr).getHostName();
            } catch (UnknownHostException ignored) {
            }
        sb.append(daddr);

        int allowed = cursor.getInt(colAllowed);
        if (allowed >= 0) {
            int pos = sb.indexOf(daddr);
            Spannable sp = new SpannableString(sb);
            ForegroundColorSpan fgsp = new ForegroundColorSpan(allowed > 0 ? colorOn : colorOff);
            sp.setSpan(fgsp, pos, pos + daddr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            notification.addLine(sp);
        } else
            notification.addLine(sb);
    }
    cursor.close();

    NotificationManagerCompat.from(this).notify(uid + 10000, notification.build());
}

From source file:eu.faircode.netguard.ServiceSinkhole.java

private Notification getEnforcingNotification(int allowed, int blocked, int hosts) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(isLockedDown(last_metered) ? R.drawable.ic_lock_outline_white_24dp
                    : R.drawable.ic_security_white_24dp)
            .setContentIntent(pi).setColor(tv.data).setOngoing(true).setAutoCancel(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setContentTitle(getString(R.string.msg_started));
    else// w w w  .  j a v a  2s . c  o  m
        builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.msg_started));

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

    if (allowed > 0 || blocked > 0 || hosts > 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            if (Util.isPlayStoreInstall(this))
                builder.setContentText(getString(R.string.msg_packages, allowed, blocked));
            else
                builder.setContentText(getString(R.string.msg_hosts, allowed, blocked, hosts));
            return builder.build();
        } else {
            NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
            notification.bigText(getString(R.string.msg_started));
            if (Util.isPlayStoreInstall(this))
                notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
            else
                notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts));
            return notification.build();
        }
    } else
        return builder.build();
}

From source file:eu.faircode.netguard.ServiceSinkhole.java

private Notification getWaitingNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setContentTitle(getString(R.string.msg_waiting));
    else//from www . j av a2 s  . co  m
        builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.msg_waiting));

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

    return builder.build();
}