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:org.microg.gms.gcm.McsService.java

private void handleAppMessage(DataMessageStanza msg) {
    database.noteAppMessage(msg.category, msg.getSerializedSize());
    GcmDatabase.App app = database.getApp(msg.category);

    Intent intent = new Intent();
    intent.setAction(ACTION_C2DM_RECEIVE);
    intent.setPackage(msg.category);/* w  w  w  .  j  a v a 2  s.c  o m*/
    intent.putExtra(EXTRA_FROM, msg.from);
    if (app.wakeForDelivery) {
        intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    } else {
        intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
    }
    if (msg.token != null)
        intent.putExtra(EXTRA_COLLAPSE_KEY, msg.token);
    for (AppData appData : msg.app_data) {
        intent.putExtra(appData.key, appData.value);
    }

    List<ResolveInfo> infos = getPackageManager().queryBroadcastReceivers(intent,
            PackageManager.GET_RESOLVED_FILTER);
    if (infos == null || infos.isEmpty()) {
        logd("No target for message, wut?");
    } else {
        for (ResolveInfo resolveInfo : infos) {
            logd("Target: " + resolveInfo);
            Intent targetIntent = new Intent(intent);
            targetIntent.setComponent(
                    new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
            sendOrderedBroadcast(targetIntent, msg.category + ".permission.C2D_MESSAGE");
        }
    }
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

/**
 * Notify the mdm that provisioning has completed. When the mdm has received the intent, stop
 * the service and notify the {@link ProfileOwnerProvisioningActivity} so that it can finish
 * itself.//from w ww . ja va  2 s .c om
 */
private void notifyMdmAndCleanup() {
    // Set DPM userProvisioningState appropriately and persist mParams for use during
    // FinalizationActivity if necessary.
    mUtils.markUserProvisioningStateInitiallyDone(this, mParams);

    if (mParams.provisioningAction.equals(ACTION_PROVISION_MANAGED_PROFILE)) {
        // Set the user_setup_complete flag on the managed-profile as setup-wizard is never run
        // for that user. This is not relevant for other cases since
        // Utils.markUserProvisioningStateInitiallyDone() communicates provisioning state to
        // setup-wizard via DPM.setUserProvisioningState() if necessary.
        mUtils.markUserSetupComplete(this, mManagedProfileOrUserInfo.id);
    }

    // If profile owner provisioning was started after current user setup is completed, then we
    // can directly send the ACTION_PROFILE_PROVISIONING_COMPLETE broadcast to the MDM.
    // But if the provisioning was started as part of setup wizard flow, we signal setup-wizard
    // should shutdown via DPM.setUserProvisioningState(), which will result in a finalization
    // intent being sent to us once setup-wizard finishes. As part of the finalization intent
    // handling we then broadcast ACTION_PROFILE_PROVISIONING_COMPLETE.
    if (mUtils.isUserSetupCompleted(this)) {
        UserHandle managedUserHandle = new UserHandle(mManagedProfileOrUserInfo.id);

        // Use an ordered broadcast, so that we only finish when the mdm has received it.
        // Avoids a lag in the transition between provisioning and the mdm.
        BroadcastReceiver mdmReceivedSuccessReceiver = new MdmReceivedSuccessReceiver(mParams.accountToMigrate,
                mParams.deviceAdminComponentName.getPackageName());

        Intent completeIntent = new Intent(ACTION_PROFILE_PROVISIONING_COMPLETE);
        completeIntent.setComponent(mParams.deviceAdminComponentName);
        completeIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES | Intent.FLAG_RECEIVER_FOREGROUND);
        if (mParams.adminExtrasBundle != null) {
            completeIntent.putExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, mParams.adminExtrasBundle);
        }

        sendOrderedBroadcastAsUser(completeIntent, managedUserHandle, null, mdmReceivedSuccessReceiver, null,
                Activity.RESULT_OK, null, null);
        ProvisionLogger.logd(
                "Provisioning complete broadcast has been sent to user " + managedUserHandle.getIdentifier());
    }
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Saves data in list and sends Intent to cycle wallpaper
 *//*from  w w  w. j  a va2 s .c o m*/
private void cycleWallpaper() {
    listAdapter.saveData();
    Intent intent = new Intent();
    intent.setAction(LiveWallpaperService.CYCLE_IMAGE);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    appContext.sendBroadcast(intent);
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Starts (or stops) download and sets download icon appropriately
 *//*from   w w  w . j  a va2s  .  c om*/
private void startDownload() {
    listAdapter.saveData();
    if (FileHandler.isDownloading) {

        DialogFactory.ActionDialogListener listener = new DialogFactory.ActionDialogListener() {

            @Override
            public void onClickRight(View v) {
                FileHandler.cancel(appContext);
                resetActionBarDownload();
                dismissDialog();
            }
        };

        DialogFactory.showActionDialog(appContext, "", "Cancel download?", listener, -1, R.string.cancel_button,
                R.string.ok_button);
    } else if (FileHandler.download(appContext)) {
        Drawable drawable = getResources().getDrawable(R.drawable.ic_cancel_white_24dp);
        drawable.setColorFilter(AppSettings.getColorFilterInt(appContext), PorterDuff.Mode.MULTIPLY);
        toolbarMenu.getItem(1).setIcon(drawable);

        if (AppSettings.resetOnManualDownload() && AppSettings.useTimer()
                && AppSettings.getTimerDuration() > 0) {
            Intent intent = new Intent();
            intent.setAction(LiveWallpaperService.DOWNLOAD_WALLPAPER);
            intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, 0, intent, 0);
            AlarmManager alarmManager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
            alarmManager.cancel(pendingIntent);
            alarmManager.setInexactRepeating(AlarmManager.RTC,
                    System.currentTimeMillis() + AppSettings.getTimerDuration(), AppSettings.getTimerDuration(),
                    pendingIntent);
        }
    }
}

From source file:de.ub0r.android.websms.WebSMSReceiver.java

@SuppressLint("InlinedApi")
private static void sendMessageToCallMeter(final Context context, final ConnectorSpec specs, final Uri u) {
    Log.d(TAG, "send broadcast to CallMeter3G");
    Intent intent = new Intent(ACTION_CM_WEBSMS);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    intent.putExtra(EXTRA_WEBSMS_URI, u.toString());
    intent.putExtra(EXTRA_WEBSMS_CONNECTOR, specs.getName().toLowerCase());
    context.sendBroadcast(intent);//ww w . java2s.c  o m
}

From source file:projekt.substratum.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();/*from  w w w. java2s. c om*/
        return true;
    case R.id.search:
        try {
            String playURL;
            if (References.checkOMS()) {
                playURL = getString(R.string.search_play_store_url);
            } else {
                playURL = getString(R.string.search_play_store_url_legacy);
            }
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(playURL));
            startActivity(i);
        } catch (ActivityNotFoundException activityNotFoundException) {
            Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.activity_missing_toast),
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        return true;

    // Begin OMS based options
    case R.id.refresh_windows:
        if (References.isPackageInstalled(getApplicationContext(), "masquerade.substratum")) {
            Intent runCommand = new Intent();
            runCommand.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            runCommand.setAction("masquerade.substratum.COMMANDS");
            runCommand.putExtra("om-commands", "om refresh");
            getApplicationContext().sendBroadcast(runCommand);
        } else {
            Root.runCommand("om refresh");
        }
        return true;
    case R.id.restart_systemui:
        Root.runCommand("pkill -f com.android.systemui");
        return true;

    // Begin RRO based options
    case R.id.reboot_device:
        Root.runCommand("reboot");
        return true;
    case R.id.soft_reboot:
        Root.runCommand("pkill -f zygote");
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.android.tv.settings.users.AppRestrictionsFragment.java

/**
 * Send a broadcast to the app to query its restrictions
 * @param packageName package name of the app with restrictions
 * @param preference the preference item for the app toggle
 *///from  w ww.j av  a2 s. c  o m
private void requestRestrictionsForApp(String packageName, AppRestrictionsPreference preference) {
    Bundle oldEntries = mUserManager.getApplicationRestrictions(packageName, mUser);
    Intent intent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES);
    intent.setPackage(packageName);
    intent.putExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE, oldEntries);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    getActivity().sendOrderedBroadcast(intent, null, new RestrictionsResultReceiver(packageName, preference),
            null, Activity.RESULT_OK, null, null);
}

From source file:cw.kop.autobackground.files.DownloadThread.java

private void finish() {
    if (AppSettings.useDownloadNotification()) {
        Notification.Builder notifyComplete = new Notification.Builder(appContext)
                .setContentTitle("Download Completed")
                .setContentText("AutoBackground downloaded " + totalDownloaded + " images")
                .setSmallIcon(R.drawable.ic_photo_white_24dp);

        Notification notification;

        if (Build.VERSION.SDK_INT >= 16) {
            notifyComplete.setPriority(Notification.PRIORITY_LOW);
            Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
            inboxStyle.setBigContentTitle("Downloaded Image Details:");

            inboxStyle.addLine("Total images enabled: " + FileHandler.getBitmapList().size());

            for (String detail : imageDetails.split(AppSettings.DATA_SPLITTER)) {
                inboxStyle.addLine(detail);
            }//from   w w  w  .j  a v a  2s. c om

            notifyComplete.setStyle(inboxStyle);
            notification = notifyComplete.build();
        } else {
            notification = notifyComplete.getNotification();
        }

        notificationManager.cancel(NOTIFICATION_ID);
        notificationManager.notify(NOTIFICATION_ID, notification);
    }

    Intent cycleIntent = new Intent();
    cycleIntent.setAction(LiveWallpaperService.CYCLE_IMAGE);
    cycleIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    appContext.sendBroadcast(cycleIntent);

    Intent resetDownloadIntent = new Intent(FileHandler.DOWNLOAD_TERMINATED);
    LocalBroadcastManager.getInstance(appContext).sendBroadcast(resetDownloadIntent);

    Intent intent = new Intent();
    intent.setAction(LiveWallpaperService.UPDATE_NOTIFICATION);
    intent.putExtra("use", AppSettings.useNotification());
    appContext.sendBroadcast(intent);

    AppSettings.checkUsedLinksSize();
    appContext = null;

    Log.i(TAG, "Download Finished");
    FileHandler.setIsDownloading(false);
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Update {@link ConnectorSpec}s.//from ww  w.  j av a 2s.  c o  m
 */
private void updateConnectors() {
    // query for connectors
    final Intent i = new Intent(Connector.ACTION_CONNECTOR_UPDATE);
    i.setFlags(i.getFlags() | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    Log.d(TAG, "send broadcast: " + i.getAction());
    newConnectorsExpected = this.getInstalledConnectorsCount() - CONNECTORS.size();
    updateProgressBar();
    this.sendBroadcast(i);
}

From source file:org.telegramsecureplus.android.NotificationsController.java

@SuppressLint("InlinedApi")
public void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) {
    if (Build.VERSION.SDK_INT < 19) {
        return;/*from w w w.j a v  a  2 s . co  m*/
    }

    ArrayList<Long> sortedDialogs = new ArrayList<>();
    HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>();
    for (int a = 0; a < pushMessages.size(); a++) {
        MessageObject messageObject = pushMessages.get(a);
        long dialog_id = messageObject.getDialogId();
        if ((int) dialog_id == 0) {
            continue;
        }

        ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id);
        if (arrayList == null) {
            arrayList = new ArrayList<>();
            messagesByDialogs.put(dialog_id, arrayList);
            sortedDialogs.add(0, dialog_id);
        }
        arrayList.add(messageObject);
    }

    HashMap<Long, Integer> oldIdsWear = new HashMap<>();
    oldIdsWear.putAll(wearNotificationsIds);
    wearNotificationsIds.clear();

    HashMap<Long, Integer> oldIdsAuto = new HashMap<>();
    oldIdsAuto.putAll(autoNotificationsIds);
    autoNotificationsIds.clear();

    for (int b = 0; b < sortedDialogs.size(); b++) {
        long dialog_id = sortedDialogs.get(b);
        ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
        int max_id = messageObjects.get(0).getId();
        int max_date = messageObjects.get(0).messageOwner.date;
        TLRPC.Chat chat = null;
        TLRPC.User user = null;
        String name;
        if (dialog_id > 0) {
            user = MessagesController.getInstance().getUser((int) dialog_id);
            if (user == null) {
                continue;
            }
        } else {
            chat = MessagesController.getInstance().getChat(-(int) dialog_id);
            if (chat == null) {
                continue;
            }
        }
        if (chat != null) {
            name = chat.title;
        } else {
            name = UserObject.getUserName(user);
        }

        Integer notificationIdWear = oldIdsWear.get(dialog_id);
        if (notificationIdWear == null) {
            notificationIdWear = wearNotificationId++;
        } else {
            oldIdsWear.remove(dialog_id);
        }

        Integer notificationIdAuto = oldIdsAuto.get(dialog_id);
        if (notificationIdAuto == null) {
            notificationIdAuto = autoNotificationId++;
        } else {
            oldIdsAuto.remove(dialog_id);
        }

        Intent msgHeardIntent = new Intent();
        msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        msgHeardIntent.setAction("org.telegramsecureplus.messenger.ACTION_MESSAGE_HEARD");
        msgHeardIntent.putExtra("dialog_id", dialog_id);
        msgHeardIntent.putExtra("max_id", max_id);
        PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent msgReplyIntent = new Intent();
        msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        msgReplyIntent.setAction("org.telegramsecureplus.messenger.ACTION_MESSAGE_REPLY");
        msgReplyIntent.putExtra("dialog_id", dialog_id);
        msgReplyIntent.putExtra("max_id", max_id);
        PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY)
                .setLabel(LocaleController.getString("Reply", R.string.Reply)).build();

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
                name).setReadPendingIntent(msgHeardPendingIntent)
                        .setReplyAction(msgReplyPendingIntent, remoteInputAuto)
                        .setLatestTimestamp((long) max_date * 1000);

        Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class);
        replyIntent.putExtra("dialog_id", dialog_id);
        replyIntent.putExtra("max_id", max_id);
        PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                .setLabel(LocaleController.getString("Reply", R.string.Reply)).build();
        String replyToString;
        if (chat != null) {
            replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name);
        } else {
            replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name);
        }
        NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
                replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build();

        String text = "";
        for (int a = messageObjects.size() - 1; a >= 0; a--) {
            MessageObject messageObject = messageObjects.get(a);
            String message = getStringForMessage(messageObject, false);
            if (message == null) {
                continue;
            }
            if (chat != null) {
                message = message.replace(" @ " + name, "");
            } else {
                message = message.replace(name + ": ", "").replace(name + " ", "");
            }
            if (text.length() > 0) {
                text += "\n\n";
            }
            text += message;

            unreadConvBuilder.addMessage(message);
        }

        TLRPC.FileLocation photoPath = null;
        if (chat != null) {
            if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0
                    && chat.photo.photo_small.local_id != 0) {
                photoPath = chat.photo.photo_small;
            }
        } else {
            if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0
                    && user.photo.photo_small.local_id != 0) {
                photoPath = user.photo.photo_small;
            }
        }

        Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
        intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
        intent.setFlags(32768);
        if (chat != null) {
            intent.putExtra("chatId", chat.id);
        } else if (user != null) {
            intent.putExtra("userId", user.id);
        }
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                ApplicationLoader.applicationContext).setContentTitle(name)
                        .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text)
                        .setColor(0xff2ca5e0).setGroupSummary(false).setContentIntent(contentIntent)
                        .extend(new NotificationCompat.WearableExtender().addAction(action))
                        .extend(new NotificationCompat.CarExtender()
                                .setUnreadConversation(unreadConvBuilder.build()))
                        .setCategory(NotificationCompat.CATEGORY_MESSAGE);
        if (photoPath != null) {
            BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
            if (img != null) {
                builder.setLargeIcon(img.getBitmap());
            }
        }

        if (chat == null && user != null && user.phone != null && user.phone.length() > 0) {
            builder.addPerson("tel:+" + user.phone);
        }

        notificationManager.notify(notificationIdWear, builder.build());
        wearNotificationsIds.put(dialog_id, notificationIdWear);
    }

    for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) {
        notificationManager.cancel(entry.getValue());
    }
}