Example usage for android.os PersistableBundle getString

List of usage examples for android.os PersistableBundle getString

Introduction

In this page you can find the example usage for android.os PersistableBundle getString.

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.example.android.droptarget.DropTargetFragment.java

/**
 * DragEvents can contain additional data packaged in a {@link PersistableBundle}.
 * Extract the extras from the event and return the String stored for the
 * {@link #EXTRA_IMAGE_INFO} entry./*  www. j  a  v  a2 s .  c o m*/
 */
private String getExtra(DragEvent event) {
    // The extras are contained in the ClipDescription in the DragEvent.
    ClipDescription clipDescription = event.getClipDescription();
    if (clipDescription != null) {
        PersistableBundle extras = clipDescription.getExtras();
        if (extras != null) {
            return extras.getString(EXTRA_IMAGE_INFO);
        }
    }
    return null;
}

From source file:com.afwsamples.testdpc.provision.PostProvisioningTask.java

@TargetApi(Build.VERSION_CODES.O)
private void maybeSetAffiliationIds(PersistableBundle extras) {
    if (extras == null) {
        return;/* w w w . jav  a2  s  . c  o m*/
    }
    String affiliationId = extras.getString(LaunchIntentUtil.EXTRA_AFFILIATION_ID);
    if (affiliationId != null) {
        mDevicePolicyManager.setAffiliationIds(getComponentName(mContext), Arrays.asList(affiliationId));
    }
}

From source file:com.android.tv.settings.about.AboutFragment.java

/**
 * Trigger client initiated action (send intent) on system update
 *//*from  www  .  j av  a  2 s.  co  m*/
private void ciActionOnSysUpdate(PersistableBundle b) {
    String intentStr = b.getString(CarrierConfigManager.KEY_CI_ACTION_ON_SYS_UPDATE_INTENT_STRING);
    if (!TextUtils.isEmpty(intentStr)) {
        String extra = b.getString(CarrierConfigManager.KEY_CI_ACTION_ON_SYS_UPDATE_EXTRA_STRING);
        String extraVal = b.getString(CarrierConfigManager.KEY_CI_ACTION_ON_SYS_UPDATE_EXTRA_VAL_STRING);

        Intent intent = new Intent(intentStr);
        if (!TextUtils.isEmpty(extra)) {
            intent.putExtra(extra, extraVal);
        }
        Log.d(TAG, "ciActionOnSysUpdate: broadcasting intent " + intentStr + " with extra " + extra + ", "
                + extraVal);
        getActivity().getApplicationContext().sendBroadcast(intent);
    }
}

From source file:eu.faircode.netguard.ServiceJob.java

private static void submit(Rule rule, PersistableBundle bundle, Context context) {
    PackageManager pm = context.getPackageManager();
    JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

    // Get english application label
    String label = null;/*from w  w w . j a  v a 2 s .c  om*/
    try {
        Configuration config = new Configuration();
        config.setLocale(new Locale("en"));
        Resources res = pm.getResourcesForApplication(rule.info.packageName);
        res.updateConfiguration(config, res.getDisplayMetrics());
        label = res.getString(rule.info.applicationInfo.labelRes);
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        CharSequence cs = rule.info.applicationInfo.loadLabel(pm);
        if (cs != null)
            label = cs.toString();
    }

    // Add application data
    bundle.putInt("uid", rule.info.applicationInfo.uid);
    bundle.putString("package", rule.info.packageName);
    bundle.putInt("version_code", rule.info.versionCode);
    bundle.putString("version_name", rule.info.versionName);
    bundle.putString("label", label);
    bundle.putInt("system", rule.system ? 1 : 0);
    try {
        bundle.putString("installer", pm.getInstallerPackageName(rule.info.packageName));
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        bundle.putString("installer", null);
    }

    // Cancel overlapping jobs
    for (JobInfo pending : scheduler.getAllPendingJobs()) {
        String type = pending.getExtras().getString("type");
        if (type != null && type.equals(bundle.getString("type"))) {
            if (type.equals("rule")) {
                int uid = pending.getExtras().getInt("uid");
                if (uid == bundle.getInt("uid")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            } else if (type.equals("host")) {
                int uid = pending.getExtras().getInt("uid");
                int version = pending.getExtras().getInt("version");
                int protocol = pending.getExtras().getInt("protocol");
                String daddr = pending.getExtras().getString("daddr");
                int dport = pending.getExtras().getInt("dport");
                if (uid == bundle.getInt("uid") && version == bundle.getInt("version")
                        && protocol == bundle.getInt("protocol") && daddr != null
                        && daddr.equals(bundle.getString("daddr")) && dport == bundle.getInt("dport")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            }
        }
    }

    // Schedule job
    ComponentName serviceName = new ComponentName(context, ServiceJob.class);
    JobInfo job = new JobInfo.Builder(++id, serviceName).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
            .setMinimumLatency(Util.isDebuggable(context) ? 10 * 1000 : 60 * 1000).setExtras(bundle)
            .setPersisted(true).build();
    if (scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS)
        Log.i(TAG, "Scheduled job=" + job.getId() + " success");
    else
        Log.e(TAG, "Scheduled job=" + job.getId() + " failed");
}