Search in sources :

Example 71 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project routerkeygenAndroid by routerkeygen.

the class UpdateCheckerService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    final LastVersion lastVersion = getLatestVersion();
    if (lastVersion == null)
        return;
    if (!Preferences.VERSION.equals(lastVersion.version)) {
        final NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_notification).setTicker(getString(R.string.update_title)).setContentTitle(getString(R.string.update_title)).setContentText(getString(R.string.update_notification, lastVersion.version)).setOnlyAlertOnce(true).setAutoCancel(true).setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(Intent.ACTION_VIEW).setData(Uri.parse(lastVersion.url)), PendingIntent.FLAG_ONE_SHOT));
        mNotificationManager.notify(UNIQUE_ID, builder.build());
    }
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 72 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project XposedInstaller by rovo89.

the class NotificationUtil method showModulesUpdatedNotification.

@SuppressWarnings("deprecation")
public static void showModulesUpdatedNotification() {
    Intent intent = new Intent(sContext, WelcomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("fragment", 0);
    PendingIntent pInstallTab = PendingIntent.getActivity(sContext, PENDING_INTENT_OPEN_INSTALL, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    String title = sContext.getString(R.string.xposed_module_updated_notification_title);
    String message = sContext.getString(R.string.xposed_module_updated_notification);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(sContext).setContentTitle(title).setContentText(message).setTicker(title).setContentIntent(pInstallTab).setVibrate(new long[] { 0 }).setAutoCancel(true).setSmallIcon(R.drawable.ic_notification).setColor(sContext.getResources().getColor(R.color.colorPrimary));
    if (Build.VERSION.SDK_INT >= 21)
        builder.setPriority(2);
    Intent iSoftReboot = new Intent(sContext, RebootReceiver.class);
    iSoftReboot.putExtra(RebootReceiver.EXTRA_SOFT_REBOOT, true);
    PendingIntent pSoftReboot = PendingIntent.getBroadcast(sContext, PENDING_INTENT_SOFT_REBOOT, iSoftReboot, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent iReboot = new Intent(sContext, RebootReceiver.class);
    PendingIntent pReboot = PendingIntent.getBroadcast(sContext, PENDING_INTENT_REBOOT, iReboot, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(0, sContext.getString(R.string.reboot), pReboot);
    builder.addAction(0, sContext.getString(R.string.soft_reboot), pSoftReboot);
    sNotificationManager.notify(null, NOTIFICATION_MODULES_UPDATED, builder.build());
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 73 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project chefly_android by chef-ly.

the class MyService method onHandleIntent.

//called automaticly when server starts, receives data as an argument
@Override
protected void onHandleIntent(Intent intent) {
    RequestMethod requestPackage = intent.getParcelableExtra(REQUEST_PACKAGE);
    String sender = intent.getStringExtra("Tag");
    Log.d(TAG, "Sender -> " + sender);
    Log.d(TAG, "Request Package Endpoint-> " + requestPackage.getEndpoint());
    String response;
    try {
        HttpConnection http = new HttpConnection();
        response = http.downloadFromFeed(requestPackage);
    } catch (IOException e) {
        //e.printStackTrace();
        return;
    }
    Log.d(TAG, "Response -> " + response);
    GsonBuilder builder = new GsonBuilder();
    //builder.registerTypeAdapter(Uri.class, new JsonDeserializer<Uri>() {
    //    @Override
    //    public Uri deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    //        return Uri.parse(json.toString());
    //    }
    //});
    Gson gson = builder.create();
    RecipeList dataItems;
    Type type = new TypeToken<RecipeList>() {
    }.getType();
    dataItems = gson.fromJson(response, type);
    Intent messageIntent = new Intent(MY_SERVICE_MESSAGE);
    messageIntent.putExtra(MY_SERVICE_RESPONSE_STRING, response);
    // messageIntent.putExtra(MY_SERVICE_PAYLOAD, "Service all done!"); //pass data back, set key value and message
    if (dataItems != null) {
        //pass back the data
        messageIntent.putExtra(MY_SERVICE_PAYLOAD, dataItems);
    } else {
        // unidentified sender - send empty parcel back
        messageIntent.putExtra(MY_SERVICE_PAYLOAD, new Parcelable() {

            @Override
            public int describeContents() {
                return 0;
            }

            @Override
            public void writeToParcel(Parcel dest, int flags) {
            }
        });
    //pass back the data
    }
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getApplicationContext());
    manager.sendBroadcast(messageIntent);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Parcel(android.os.Parcel) Gson(com.google.gson.Gson) Intent(android.content.Intent) Parcelable(android.os.Parcelable) IOException(java.io.IOException) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Type(java.lang.reflect.Type) RecipeList(com.se491.chef_ly.model.RecipeList)

Example 74 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project kdeconnect-android by KDE.

the class SharePlugin method onPackageReceived.

@Override
public boolean onPackageReceived(NetworkPackage np) {
    try {
        if (np.hasPayload()) {
            Log.i("SharePlugin", "hasPayload");
            int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
            } else if (permissionCheck == PackageManager.PERMISSION_DENIED) {
                // TODO Request Permission for storage
                Log.i("SharePlugin", "no Permission for Storage");
                return false;
            }
            final InputStream input = np.getPayload();
            final long fileLength = np.getPayloadSize();
            final String originalFilename = np.getString("filename", Long.toString(System.currentTimeMillis()));
            //We need to check for already existing files only when storing in the default path.
            //User-defined paths use the new Storage Access Framework that already handles this.
            final boolean customDestination = ShareSettingsActivity.isCustomDestinationEnabled(context);
            final String defaultPath = ShareSettingsActivity.getDefaultDestinationDirectory().getAbsolutePath();
            final String filename = customDestination ? originalFilename : FilesHelper.findNonExistingNameForNewFile(defaultPath, originalFilename);
            String displayName = FilesHelper.getFileNameWithoutExt(filename);
            final String mimeType = FilesHelper.getMimeTypeFromFile(filename);
            if ("*/*".equals(mimeType)) {
                displayName = filename;
            }
            final DocumentFile destinationFolderDocument = ShareSettingsActivity.getDestinationDirectory(context);
            final DocumentFile destinationDocument = destinationFolderDocument.createFile(mimeType, displayName);
            final OutputStream destinationOutput = context.getContentResolver().openOutputStream(destinationDocument.getUri());
            final Uri destinationUri = destinationDocument.getUri();
            final int notificationId = (int) System.currentTimeMillis();
            Resources res = context.getResources();
            final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(res.getString(R.string.incoming_file_title, device.getName())).setContentText(res.getString(R.string.incoming_file_text, filename)).setTicker(res.getString(R.string.incoming_file_title, device.getName())).setSmallIcon(android.R.drawable.stat_sys_download).setAutoCancel(true).setOngoing(true).setProgress(100, 0, true);
            final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    boolean successful = true;
                    try {
                        byte[] data = new byte[1024];
                        long progress = 0, prevProgressPercentage = 0;
                        int count;
                        while ((count = input.read(data)) >= 0) {
                            progress += count;
                            destinationOutput.write(data, 0, count);
                            if (fileLength > 0) {
                                if (progress >= fileLength)
                                    break;
                                long progressPercentage = (progress * 10 / fileLength);
                                if (progressPercentage != prevProgressPercentage) {
                                    prevProgressPercentage = progressPercentage;
                                    builder.setProgress(100, (int) progressPercentage * 10, false);
                                    NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build());
                                }
                            }
                        //else Log.e("SharePlugin", "Infinite loop? :D");
                        }
                        destinationOutput.flush();
                    } catch (Exception e) {
                        successful = false;
                        Log.e("SharePlugin", "Receiver thread exception");
                        e.printStackTrace();
                    } finally {
                        try {
                            destinationOutput.close();
                        } catch (Exception e) {
                        }
                        try {
                            input.close();
                        } catch (Exception e) {
                        }
                    }
                    try {
                        Log.i("SharePlugin", "Transfer finished: " + destinationUri.getPath());
                        //Update the notification and allow to open the file from it
                        Resources res = context.getResources();
                        String message = successful ? res.getString(R.string.received_file_title, device.getName()) : res.getString(R.string.received_file_fail_title, device.getName());
                        builder.setContentTitle(message).setTicker(message).setSmallIcon(android.R.drawable.stat_sys_download_done).setAutoCancel(true).setProgress(100, 100, false).setOngoing(false);
                        // TODO use FileProvider for >Nougat
                        if (Build.VERSION.SDK_INT < 24) {
                            if (successful) {
                                Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.setDataAndType(destinationUri, mimeType);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
                                stackBuilder.addNextIntent(intent);
                                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
                                builder.setContentText(res.getString(R.string.received_file_text, destinationDocument.getName())).setContentIntent(resultPendingIntent);
                            }
                        }
                        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                        if (prefs.getBoolean("share_notification_preference", true)) {
                            builder.setDefaults(Notification.DEFAULT_ALL);
                        }
                        NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build());
                        if (successful) {
                            if (!customDestination && Build.VERSION.SDK_INT >= 12) {
                                Log.i("SharePlugin", "Adding to downloads");
                                DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
                                manager.addCompletedDownload(destinationUri.getLastPathSegment(), device.getName(), true, mimeType, destinationUri.getPath(), fileLength, false);
                            } else {
                                //Make sure it is added to the Android Gallery anyway
                                MediaStoreHelper.indexFile(context, destinationUri);
                            }
                        }
                    } catch (Exception e) {
                        Log.e("SharePlugin", "Receiver thread exception");
                        e.printStackTrace();
                    }
                }
            }).start();
        } else if (np.has("text")) {
            Log.i("SharePlugin", "hasText");
            String text = np.getString("text");
            if (Build.VERSION.SDK_INT >= 11) {
                ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(text);
            } else {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setText(text);
            }
            Toast.makeText(context, R.string.shareplugin_text_saved, Toast.LENGTH_LONG).show();
        } else if (np.has("url")) {
            String url = np.getString("url");
            Log.i("SharePlugin", "hasUrl: " + url);
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (openUrlsDirectly) {
                context.startActivity(browserIntent);
            } else {
                Resources res = context.getResources();
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
                stackBuilder.addNextIntent(browserIntent);
                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
                Notification noti = new NotificationCompat.Builder(context).setContentTitle(res.getString(R.string.received_url_title, device.getName())).setContentText(res.getString(R.string.received_url_text, url)).setContentIntent(resultPendingIntent).setTicker(res.getString(R.string.received_url_title, device.getName())).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).build();
                NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                NotificationHelper.notifyCompat(notificationManager, (int) System.currentTimeMillis(), noti);
            }
        } else {
            Log.e("SharePlugin", "Error: Nothing attached!");
        }
    } catch (Exception e) {
        Log.e("SharePlugin", "Exception");
        e.printStackTrace();
    }
    return true;
}
Also used : OutputStream(java.io.OutputStream) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Uri(android.net.Uri) DownloadManager(android.app.DownloadManager) Notification(android.app.Notification) NotificationCompat(android.support.v4.app.NotificationCompat) Context(android.content.Context) ClipboardManager(android.content.ClipboardManager) DocumentFile(android.support.v4.provider.DocumentFile) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) InputStream(java.io.InputStream) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Example 75 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project NetGuard by M66B.

the class ServiceSinkhole method notifyNewApplication.

public void notifyNewApplication(int uid) {
    if (uid < 0)
        return;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    try {
        // Get application name
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, this));
        // Get application info
        PackageManager pm = getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, this);
        // Build notification
        Intent main = new Intent(this, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(this, uid, 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).setAutoCancel(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(getString(R.string.app_name)).setContentText(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 = getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = 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(this, 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(this, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action wAction = new NotificationCompat.Action.Builder(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, getString(wifi ? R.string.title_allow_wifi : R.string.title_block_wifi), piWifi).build();
        builder.addAction(wAction);
        // Build mobile action
        Intent riOther = new Intent(this, 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(this, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action oAction = new NotificationCompat.Action.Builder(other ? R.drawable.other_on : R.drawable.other_off, getString(other ? R.string.title_allow_other : R.string.title_block_other), piOther).build();
        builder.addAction(oAction);
        // Show notification
        if (internet)
            NotificationManagerCompat.from(this).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(getString(R.string.msg_installed_n));
            else
                expanded.bigText(getString(R.string.msg_installed, name));
            expanded.setSummaryText(getString(R.string.title_internet));
            NotificationManagerCompat.from(this).notify(uid, expanded.build());
        }
    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SpannableString(android.text.SpannableString) PackageManager(android.content.pm.PackageManager) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) TypedValue(android.util.TypedValue)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)109 PendingIntent (android.app.PendingIntent)89 Intent (android.content.Intent)82 NotificationManager (android.app.NotificationManager)36 Notification (android.app.Notification)31 Builder (android.support.v4.app.NotificationCompat.Builder)19 Context (android.content.Context)18 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)15 Uri (android.net.Uri)14 Bundle (android.os.Bundle)13 View (android.view.View)13 TextView (android.widget.TextView)11 Bitmap (android.graphics.Bitmap)10 IOException (java.io.IOException)10 RemoteViews (android.widget.RemoteViews)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.app.AlertDialog)8 DialogInterface (android.content.DialogInterface)7 Dialog (android.app.Dialog)6 Paint (android.graphics.Paint)6