Example usage for android.content Intent FLAG_EXCLUDE_STOPPED_PACKAGES

List of usage examples for android.content Intent FLAG_EXCLUDE_STOPPED_PACKAGES

Introduction

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

Prototype

int FLAG_EXCLUDE_STOPPED_PACKAGES

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

Click Source Link

Document

If set, this intent will not 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  a2 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");
        }
    }
}