Example usage for android.content Intent FLAG_INCLUDE_STOPPED_PACKAGES

List of usage examples for android.content Intent FLAG_INCLUDE_STOPPED_PACKAGES

Introduction

In this page you can find the example usage for android.content Intent FLAG_INCLUDE_STOPPED_PACKAGES.

Prototype

int FLAG_INCLUDE_STOPPED_PACKAGES

To view the source code for android.content Intent FLAG_INCLUDE_STOPPED_PACKAGES.

Click Source Link

Document

If set, this intent will always match any components in packages that are currently stopped.

Usage

From source file:br.com.virtz.www.cfcmob.MyMessagingService.java

private Intent createIntent(int conversationId, String action) {
    return new Intent().addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).setAction(action)
            .putExtra(CONVERSATION_ID, conversationId);
}

From source file:com.example.android.messagingservice.MessagingService.java

private Intent getMessageReadIntent(int id) {
    return new Intent().addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).setAction(READ_ACTION)
            .putExtra(CONVERSATION_ID, id);
}

From source file:cz.maresmar.sfm.service.plugin.PluginUtils.java

/**
 * Starts plugin according to API level//from www  . j  av  a  2s . c om
 *
 * @param context Some valid context
 * @param intent  Intent of plugin to be started
 * @see JobIntentService#enqueueWork(Context, ComponentName, int, Intent)
 */
public static void startPlugin(@NonNull Context context, @NonNull Intent intent) {
    // Test if the plugin exists
    PackageManager manager = context.getPackageManager();
    if (manager.queryIntentServices(intent, 0).size() != 1) {
        Timber.e("Plugin %s not found", intent.getComponent());
        throw new IllegalArgumentException("Plugin not found " + intent.getComponent());
    }

    // Finds jobId for selected plugin
    String pluginName = ProviderContract.buildString(intent.getComponent());
    int jobId;
    if (!mPluginsIds.containsKey(pluginName)) {
        jobId = mPluginsIds.size();
        mPluginsIds.put(pluginName, jobId);
    } else {
        jobId = mPluginsIds.get(pluginName);
    }

    // Starts plugin according to API level
    if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
            || (context.getPackageName().equals(intent.getComponent().getPackageName()))) {
        JobIntentService.enqueueWork(context, intent.getComponent(), jobId, intent);
    } else {
        // On Android >= O with external plugin use BroadcastContract.BROADCAST_PLAN_RUN to
        // start plugin, because planning of external APK's service is not allowed

        Intent plan = new Intent();
        // Explicitly select a package to communicate with
        plan.setPackage(intent.getComponent().getPackageName());
        plan.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

        plan.setAction(ActionContract.BROADCAST_PLAN_RUN);
        plan.putExtra(ActionContract.EXTRA_JOB_ID, jobId);
        plan.putExtra(ActionContract.EXTRA_INTENT_TO_DO, intent);
        context.sendBroadcast(plan);
    }
}

From source file:com.example.android.messagingservice.MessagingService.java

private Intent getMessageReplyIntent(int conversationId) {
    return new Intent().addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).setAction(REPLY_ACTION)
            .putExtra(CONVERSATION_ID, conversationId);
}

From source file:ro.decode.drivenanalytics.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param type GCM message received./*ww w.ja  va  2s  . co  m*/
 */
private void sendNotification(String type) {

    //maintenance_due
    //recall
    //trouble_light_decoded
    //new_accessory
    //low_gas
    //security_event

    Intent intent = new Intent(this, MainActivity.class);

    if (type != null) {

        if (type.equals("maintenance_due"))
            intent = new Intent(this, MainActivity.class);

        if (type.equals("recall"))
            intent = new Intent(this, RecallActivity.class);

        if (type.equals("trouble_light_decoded"))
            intent = new Intent(this, TroubleLightActivity.class);

        if (type.equals("new_accessory"))
            intent = new Intent(this, AccesoriesListActivity.class);

        if (type.equals("low_gas")) {
            intent = new Intent(this, MainActivity.class);
            intent.putExtra("tab", 1);
        }

        if (type.equals("security_event")) {
            intent = new Intent(this, MainActivity.class);
            intent.putExtra("tab", 3);
        }
    }

    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    /* PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
        PendingIntent.FLAG_ONE_SHOT);
            
     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.car_loading)
        .setContentTitle("GCM Message")
        .setContentText(type)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent);
            
     NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            
     notificationManager.notify(0, notificationBuilder.build());*/
}

From source file:nl.hnogames.domoticz.Utils.NotificationUtil.java

private static Intent getMessageReadIntent() {
    return new Intent().addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).setAction(MESSAGE_READ_ACTION)
            .putExtra(MESSAGE_CONVERSATION_ID_KEY, NOTIFICATION_ID);
}

From source file:nl.hnogames.domoticz.Utils.NotificationUtil.java

private static Intent getMessageReplyIntent() {
    return new Intent().addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).setAction(MESSAGE_REPLY_ACTION)
            .putExtra(MESSAGE_CONVERSATION_ID_KEY, NOTIFICATION_ID);
}

From source file:com.vinexs.eeb.receiver.BaseReceiverGCM.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public void onMessageTypeReceive(Context context, Intent intent) {
    notifyMgr = NotificationManagerCompat.from(context);
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(context);
    int notifyId = setting.getInt("notifyId", new Random().nextInt(65535));
    Bundle receIntent = intent.getExtras();
    try {//from   ww  w  .  ja v  a2 s .c  om
        if (!receIntent.containsKey("contentTitle") || !receIntent.containsKey("contentText")) {
            throw new Exception("Message don't contain necessary data.");
        }

        if (builder == null) {
            builder = new NotificationCompat.Builder(context);
            contentTitle = receIntent.getCharSequence("contentTitle");
            contentText = receIntent.getCharSequence("contentText");

            builder.setDefaults(Notification.DEFAULT_ALL).setContentTitle(contentTitle)
                    .setContentText(contentText).setSmallIcon(getMonoColorIcon())
                    .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true);
            try {
                if (Build.VERSION.SDK_INT < 14 || !receIntent.containsKey("largeIcon")) {
                    throw new Exception("Message don't contain [largeIcon] or device SDK lower than 14.");
                }
                String bigIconUrl = receIntent.getString("largeIcon");
                if (bigIconUrl == null || bigIconUrl.isEmpty()) {
                    throw new Exception("Message [largeIcon] is empty.");
                }
                HttpURLConnection connection = (HttpURLConnection) new URL(bigIconUrl).openConnection();
                connection.setDoInput(true);
                connection.connect();
                Bitmap bigIcon = BitmapFactory.decodeStream(connection.getInputStream());
                builder.setLargeIcon(bigIcon);
                // Add backgroud to wearable
                NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
                wearableExtender.setBackground(bigIcon);
                builder.extend(wearableExtender);
                // Set accent color
                int[] attrs = new int[] { R.attr.colorAccent };
                TypedArray ta = context.obtainStyledAttributes(attrs);
                String colorAccent = ta.getString(0);
                ta.recycle();
                builder.setColor(Color.parseColor(colorAccent));
            } catch (Exception e) {
                builder.setLargeIcon(
                        BitmapFactory.decodeResource(context.getResources(), getApplicationIcon()));
            }
            try {
                if (!receIntent.containsKey("ticker")) {
                    throw new Exception("Message don't contain [ticker].");
                }
                builder.setTicker(receIntent.getCharSequence("ticker"));
            } catch (Exception e) {
                builder.setTicker(receIntent.getCharSequence("contentText"));
            }
            if (Build.VERSION.SDK_INT >= 16) {
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
            }
        } else {
            contentText = contentText + "\n" + receIntent.getCharSequence("contentText");
            messageNum++;
            builder.setContentTitle(Utility.getAppName(context)).setContentText(contentText)
                    .setTicker(receIntent.getCharSequence("contentText")).setNumber(messageNum);
        }

        if (Build.VERSION.SDK_INT >= 16) {
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
        }

        Intent actionIntent = new Intent(context, getLauncherClass());
        if (receIntent.containsKey("intentAction")) {
            actionIntent.putExtra("onNewIntentAction", receIntent.getCharSequence("intentAction"));
        }
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, actionIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(contentIntent);

        notifyMgr.notify(notifyId, builder.build());
    } catch (Exception e) {
        Log.d("GoogleCloudMessaging",
                "Exception occurred while show message as notification -> " + e.toString());
        e.printStackTrace();
    }
}

From source file:cw.kop.autobackground.LiveWallpaperService.java

private void setIntents() {
    Intent downloadIntent = new Intent(LiveWallpaperService.DOWNLOAD_WALLPAPER);
    downloadIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    pendingDownloadIntent = PendingIntent.getBroadcast(this, 0, downloadIntent, 0);

    pendingIntervalIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(LiveWallpaperService.UPDATE_WALLPAPER), 0);
    pendingToastIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.TOAST_LOCATION),
            0);//from  w w w.java 2 s  . c  om
    pendingCopyIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.COPY_IMAGE), 0);
    pendingCycleIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.CYCLE_IMAGE), 0);
    pendingDeleteIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.DELETE_IMAGE), 0);
    pendingOpenIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.OPEN_IMAGE), 0);
    pendingPinIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.PIN_IMAGE), 0);
    pendingPreviousIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.PREVIOUS_IMAGE),
            0);
    pendingShareIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.SHARE_IMAGE), 0);
    pendingGameIntent = PendingIntent.getBroadcast(this, 0, new Intent(LiveWallpaperService.TOGGLE_GAME), 0);
    pendingAppIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
}