Example usage for android.app PendingIntent getService

List of usage examples for android.app PendingIntent getService

Introduction

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

Prototype

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

Source Link

Document

Retrieve a PendingIntent that will start a service, like calling Context#startService Context.startService() .

Usage

From source file:com.prey.actions.geofences.GeofenceController.java

private void addZones(final Context ctx) {
    List<com.google.android.gms.location.Geofence> mGeofenceList = new ArrayList<Geofence>();
    final List<GeofenceDto> listToBdAdd = new ArrayList<GeofenceDto>();
    String infoAdd = "[";
    for (int i = 0; listWeb != null && i < listWeb.size(); i++) {
        GeofenceDto geo = listWeb.get(i);
        if (!mapBD.containsKey(geo.getId())) {
            listToBdAdd.add(geo);/*from  w w w . j  a  va 2 s.c  om*/
            PreyLogger.d("__[START]___________id:" + geo.name + " lat:" + geo.latitude + " long:"
                    + geo.longitude + " ra:" + geo.radius + " expires:" + geo.expires);
            int transitionTypes = com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_ENTER
                    | com.google.android.gms.location.Geofence.GEOFENCE_TRANSITION_EXIT;

            mGeofenceList.add(new com.google.android.gms.location.Geofence.Builder().setRequestId(geo.id)
                    .setCircularRegion(geo.latitude, geo.longitude, geo.radius)
                    .setExpirationDuration(Geofence.NEVER_EXPIRE).setTransitionTypes(transitionTypes).build());

            infoAdd += geo.id;
            if (i + 1 < listWeb.size()) {
                infoAdd += ",";
            }
        }
    }

    infoAdd += "]";
    final String infoExtra = infoAdd;
    PreyLogger.d("infoAdd:" + infoExtra);

    GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL);
    builder.addGeofences(mGeofenceList);
    GeofencingRequest geofencingRequest = builder.build();
    if (mGoogleApiClient.isConnected()) {
        PreyLogger.d("---->isConnected");
        try {
            Intent intent = new Intent(ctx, GeofenceIntentService.class);
            PendingIntent pendingIntent = PendingIntent.getService(ctx, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M
                    || ActivityCompat.checkSelfPermission(ctx,
                            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                PendingResult<Status> result = LocationServices.GeofencingApi.addGeofences(mGoogleApiClient,
                        geofencingRequest, pendingIntent);
                result.setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        PreyLogger.d("*********************connectionAddListener  status");
                        if (status.isSuccess()) {
                            PreyLogger.d("********saveGeofence");
                            sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "started", infoExtra));
                            GeofenceDataSource dataSource = new GeofenceDataSource(ctx);
                            for (int i = 0; listToBdAdd != null && i < listToBdAdd.size(); i++) {
                                dataSource.createGeofence(listToBdAdd.get(i));
                            }
                        } else {
                            PreyLogger.d("*********************Registering geofence failed: "
                                    + status.getStatusMessage() + " : " + status.getStatusCode());
                            sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "failed",
                                    "status:" + status.isSuccess()));
                        }
                    }
                });
            }

        } catch (Exception e) {
            PreyLogger.e("error ---->isConnected:" + e.getMessage(), e);
            sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "failed", "error:" + e.getMessage()));
        }
    } else {
        PreyLogger.d("not connect mGoogleApiClient 3");
        sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "failed", "not connect mGoogleApiClient"));
    }
}

From source file:com.sleekcoder.weardemo.NotificationUpdateService.java

private void buildWearableOnlyNotification(String title, String content, int notificationId,
        boolean withDismissal, Bitmap bitmap) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(content)
            .setLargeIcon(bitmap);/*w  w  w  . j a  va  2 s. co m*/

    if (withDismissal) {
        Intent dismissIntent = new Intent(Constants.ACTION_DISMISS);
        dismissIntent.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.BOTH_ID);
        PendingIntent pendingIntent = PendingIntent.getService(this, 0, dismissIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setDeleteIntent(pendingIntent);
    }

    NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
    secondPageStyle.setBigContentTitle("Page 2").bigText("This is the second page of the notification");

    Notification secondPageNotification = new NotificationCompat.Builder(this).setStyle(secondPageStyle)
            .build();

    Notification twoPageNotification = new NotificationCompat.WearableExtender().addPage(secondPageNotification)
            .extend(builder).build();

    NotificationManagerCompat.from(this).notify(notificationId, twoPageNotification);
}

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

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*  w  ww.ja va 2s.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:cz.msebera.unbound.dns.UnboundService.java

private void goForeground() {
    if (mIsForeground) {
        return;/*from w  w w. j ava 2  s. co  m*/
    }

    Intent stopIntent = new Intent(getApplicationContext(), UnboundService.class);
    stopIntent.setAction(ACTION_STOP);
    PendingIntent stopPendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_STOP,
            stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder(
            android.R.drawable.ic_media_pause, getString(R.string.menu_stop), stopPendingIntent).build();
    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setContentTitle(getString(R.string.app_name)).setSmallIcon(R.mipmap.ic_launcher)
            .setPriority(Notification.PRIORITY_MIN).setCategory(NotificationCompat.CATEGORY_SERVICE)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setColor(Color.RED).addAction(stopAction)
            .setWhen(System.currentTimeMillis()).setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
            .setOngoing(true).build();
    startForeground(NOTIFICATION_ID, notification);
    mIsForeground = true;
}

From source file:com.master.metehan.filtereagle.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*from  w  w w. j a va 2 s .c  om*/

    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, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.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)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        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);
            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.zhengde163.netguard.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;//  w ww.j  a v  a2 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, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        //            Util.setTheme(context);
        context.setTheme(R.style.AppThemeBlue);
        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)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        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);
            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:net.olejon.spotcommander.WebViewActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Google API client
    mGoogleApiClient = new GoogleApiClient.Builder(mContext).addApiIfAvailable(Wearable.API).build();

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Hide status bar?
    if (mTools.getDefaultSharedPreferencesBoolean("HIDE_STATUS_BAR"))
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Power manager
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    //noinspection deprecation
    mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "wakeLock");

    // Settings/*from   w w w  .j  a v  a 2 s  .c  o m*/
    mTools.setSharedPreferencesBoolean("CAN_CLOSE_COVER", false);

    // Current network
    mCurrentNetwork = mTools.getCurrentNetwork();

    // Computer
    final long computerId = mTools.getSharedPreferencesLong("LAST_COMPUTER_ID");

    final String[] computer = mTools.getComputer(computerId);

    final String uri = computer[0];
    final String username = computer[1];
    final String password = computer[2];

    // Layout
    setContentView(R.layout.activity_webview);

    // Status bar color
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mStatusBarPrimaryColor = getWindow().getStatusBarColor();
        mStatusBarCoverArtColor = mStatusBarPrimaryColor;
    }

    // Notification
    mPersistentNotificationIsSupported = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN);

    if (mPersistentNotificationIsSupported) {
        final Intent launchActivityIntent = new Intent(mContext, MainActivity.class);
        launchActivityIntent.setAction("android.intent.action.MAIN");
        launchActivityIntent.addCategory("android.intent.category.LAUNCHER");
        mLaunchActivityPendingIntent = PendingIntent.getActivity(mContext, 0, launchActivityIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent hideIntent = new Intent(mContext, RemoteControlIntentService.class);
        hideIntent.setAction("hide_notification");
        hideIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mHidePendingIntent = PendingIntent.getService(mContext, 0, hideIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent previousIntent = new Intent(mContext, RemoteControlIntentService.class);
        previousIntent.setAction("previous");
        previousIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mPreviousPendingIntent = PendingIntent.getService(mContext, 0, previousIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent playPauseIntent = new Intent(mContext, RemoteControlIntentService.class);
        playPauseIntent.setAction("play_pause");
        playPauseIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mPlayPausePendingIntent = PendingIntent.getService(mContext, 0, playPauseIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent nextIntent = new Intent(mContext, RemoteControlIntentService.class);
        nextIntent.setAction("next");
        nextIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mNextPendingIntent = PendingIntent.getService(mContext, 0, nextIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent volumeDownIntent = new Intent(mContext, RemoteControlIntentService.class);
        volumeDownIntent.setAction("adjust_spotify_volume_down");
        volumeDownIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mVolumeDownPendingIntent = PendingIntent.getService(mContext, 0, volumeDownIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        final Intent volumeUpIntent = new Intent(mContext, RemoteControlIntentService.class);
        volumeUpIntent.setAction("adjust_spotify_volume_up");
        volumeUpIntent.putExtra(RemoteControlIntentService.REMOTE_CONTROL_INTENT_SERVICE_EXTRA, computerId);
        mVolumeUpPendingIntent = PendingIntent.getService(mContext, 0, volumeUpIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        mNotificationManager = NotificationManagerCompat.from(mContext);
        mNotificationBuilder = new NotificationCompat.Builder(mContext);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
            mNotificationBuilder.setPriority(Notification.PRIORITY_MAX);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mNotificationBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
            mNotificationBuilder.setCategory(Notification.CATEGORY_TRANSPORT);
        }
    }

    // Web view
    mWebView = (WebView) findViewById(R.id.webview_webview);

    mWebView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.background));
    mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

    mWebView.setWebViewClient(new WebViewClient() {
        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url != null && !url.contains(uri)
                    && !url.contains("olejon.net/code/spotcommander/api/1/spotify/")
                    && !url.contains("accounts.spotify.com/") && !url.contains("facebook.com/")) {
                view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

                return true;
            }

            return false;
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView view, @NonNull HttpAuthHandler handler, String host,
                String realm) {
            if (handler.useHttpAuthUsernamePassword()) {
                handler.proceed(username, password);
            } else {
                handler.cancel();

                mWebView.stopLoading();

                mTools.showToast(getString(R.string.webview_authentication_failed), 1);

                mTools.navigateUp(mActivity);
            }
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest webResourceRequest,
                WebResourceError webResourceError) {
            mWebView.stopLoading();

            mTools.showToast(getString(R.string.webview_error), 1);

            mTools.navigateUp(mActivity);
        }

        @Override
        public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) {
            handler.cancel();

            mWebView.stopLoading();

            new MaterialDialog.Builder(mContext).title(R.string.webview_dialog_ssl_error_title)
                    .content(getString(R.string.webview_dialog_ssl_error_message))
                    .positiveText(R.string.webview_dialog_ssl_error_positive_button)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            finish();
                        }
                    }).contentColorRes(R.color.black).show();
        }
    });

    // User agent
    mProjectVersionName = mTools.getProjectVersionName();

    final String uaAppend1 = (!username.equals("") && !password.equals("")) ? "AUTHENTICATION_ENABLED " : "";
    final String uaAppend2 = (mTools.getSharedPreferencesBoolean("WEAR_CONNECTED")) ? "WEAR_CONNECTED " : "";
    final String uaAppend3 = (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
            && !mTools.getDefaultSharedPreferencesBoolean("HARDWARE_ACCELERATED_ANIMATIONS"))
                    ? "DISABLE_CSSTRANSITIONS DISABLE_CSSTRANSFORMS3D "
                    : "";

    // Web settings
    final WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(false);
    webSettings.setUserAgentString(getString(R.string.webview_user_agent, webSettings.getUserAgentString(),
            mProjectVersionName, uaAppend1, uaAppend2, uaAppend3));

    // Load app
    if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
    } else {
        mWebView.loadUrl(uri);
    }

    // JavaScript interface
    mWebView.addJavascriptInterface(new JavaScriptInterface(), "Android");
}

From source file:alaindc.crowdroid.GeofenceIntentService.java

private PendingIntent getGeofencePendingIntent(int sensor_type) {
    Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
    return PendingIntent.getService(this, 0, intent, sensor_type);
}

From source file:com.nextgis.maplibui.service.LayerFillService.java

@Override
public void onCreate() {
    mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Bitmap largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_notification_download, getResources());

    mProgressIntent = new Intent(ACTION_UPDATE);
    Intent intent = new Intent(this, LayerFillService.class);
    intent.setAction(ACTION_STOP);/* w w w  .ja va 2  s  . com*/
    PendingIntent stopService = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    intent.setAction(ACTION_SHOW);
    PendingIntent showProgressDialog = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setSmallIcon(R.drawable.ic_notification_download).setLargeIcon(largeIcon).setAutoCancel(false)
            .setOngoing(true).setContentIntent(showProgressDialog)
            .addAction(R.drawable.ic_action_cancel_dark, getString(R.string.tracks_stop), stopService);
    mIsCanceled = false;

    mQueue = new LinkedList<>();
    mIsRunning = false;
    mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle resultData = msg.getData();
            Toast.makeText(LayerFillService.this, resultData.getString(BUNDLE_MSG_KEY), Toast.LENGTH_LONG)
                    .show();
        }
    };

}

From source file:edu.mit.media.funf.probe.Probe.java

private void loadRequestsIntent(Intent currentIntent) {
    if (isRequestsIntent(currentIntent)) {
        Log.d(TAG, "Is requests intent.");
        requestsIntent = currentIntent;//from  ww w  .jav a 2s.c  o m
    } else {
        // Attempt to grab pending intent and send Otherwise initialize requestsIntent
        Intent internalRunIntent = getRequestsIntent();
        PendingIntent selfLaunchingIntent = PendingIntent.getService(this, 0, internalRunIntent,
                PendingIntent.FLAG_NO_CREATE);
        if (selfLaunchingIntent == null) {
            requestsIntent = internalRunIntent;
        } else {
            try {
                Log.i(TAG, "Sending requests pending intent and waiting");
                selfLaunchingIntent.send();
                queueIntent(currentIntent, true);
                pauseQueueUntilIntentReceived(internalRunIntent, null);
            } catch (CanceledException e) {
                Log.e(TAG, "CANCELLED INTERNAL RUN INTENT");
                requestsIntent = internalRunIntent;
            }
        }
    }
}