Example usage for android.content ComponentName getClass

List of usage examples for android.content ComponentName getClass

Introduction

In this page you can find the example usage for android.content ComponentName getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.google.android.media.tv.companionlibrary.EpgSyncJobService.java

/**
 * Manually requests a job to run now.//from w  w  w. jav a  2  s.co m
 *
 * To check the current status of the sync, register a {@link android.content.BroadcastReceiver}
 * with an {@link android.content.IntentFilter} which checks for the action
 * {@link #ACTION_SYNC_STATUS_CHANGED}.
 * <p />
 * The sync status is an extra parameter in the {@link Intent} with key
 * {@link #SYNC_STATUS}. The sync status is either {@link #SYNC_STARTED} or
 * {@link #SYNC_FINISHED}.
 * <p />
 * Check that the value of {@link #BUNDLE_KEY_INPUT_ID} matches your
 * {@link android.media.tv.TvInputService}. If you're calling this from your setup activity,
 * you can get the extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}.
 * <p />
 * @param context Application's context.
 * @param inputId Component name for the app's TvInputService. This can be received through an
 * Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}.
 * @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync,
 * this should be relatively short. For a background sync this should be long.
 * @param jobServiceComponent The {@link EpgSyncJobService} class that will run.
 */
public static void requestImmediateSync(Context context, String inputId, long syncDuration,
        ComponentName jobServiceComponent) {
    if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) {
        throw new IllegalArgumentException("This class does not extend EpgSyncJobService");
    }
    PersistableBundle persistableBundle = new PersistableBundle();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    }
    persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration);
    JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID, jobServiceComponent);
    JobInfo jobInfo = builder.setExtras(persistableBundle)
            .setOverrideDeadline(EpgSyncJobService.OVERRIDE_DEADLINE_MILLIS)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build();
    scheduleJob(context, jobInfo);
    if (DEBUG) {
        Log.d(TAG, "Single job scheduled");
    }
}

From source file:com.google.android.media.tv.companionlibrary.EpgSyncJobService.java

/**
 * Initializes a job that will periodically update the app's channels and programs.
 *
 * @param context Application's context.
 * @param inputId Component name for the app's TvInputService. This can be received through an
 * Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}.
 * @param jobServiceComponent The {@link EpgSyncJobService} component name that will run.
 * @param fullSyncPeriod The period between when the job will run a full background sync in
 * milliseconds.//from  ww  w  .  j a v  a 2  s  .  c om
 * @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync,
 * this should be relatively short. For a background sync this should be long.
 */
public static void setUpPeriodicSync(Context context, String inputId, ComponentName jobServiceComponent,
        long fullSyncPeriod, long syncDuration) {
    if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) {
        throw new IllegalArgumentException("This class does not extend EpgSyncJobService");
    }
    PersistableBundle persistableBundle = new PersistableBundle();
    persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration);
    JobInfo.Builder builder = new JobInfo.Builder(PERIODIC_SYNC_JOB_ID, jobServiceComponent);
    JobInfo jobInfo = builder.setExtras(persistableBundle).setPeriodic(fullSyncPeriod).setPersisted(true)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build();
    scheduleJob(context, jobInfo);
    if (DEBUG) {
        Log.d(TAG, "Job has been scheduled for every " + fullSyncPeriod + "ms");
    }
}

From source file:com.arctech.gcm.MyGcmListenerService.java

public boolean checkApp() {
    ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);

    // get the info from the currently running task
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);

    //        ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
    //        List<ActivityManager.RunningTaskInfo> services = activityManager
    //                .getRunningTasks(Integer.MAX_VALUE);

    ComponentName componentInfo = taskInfo.get(0).topActivity;
    Log.i("Package Activity", " " + componentInfo.getPackageName());
    Log.i("Class Activity", " " + componentInfo.getClassName());
    if (componentInfo.getClassName().equalsIgnoreCase("com.arctech.stikyhive.StikyChatMoreActivity")) {
        Log.i(TAG, "Chat More Activity");
        StikyChatMoreActivity.flagGCM = true;
        flagNoti = false;/*from w ww. ja v  a  2s . c o  m*/
        Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
        LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
        return false;
    } else if (componentInfo.getClassName().equalsIgnoreCase("com.arctech.stikyhive.ChattingActivity")) {
        Log.i("TAG", componentInfo.getClass() + " ");
        Intent registrationComplete = new Intent(QuickstartPreferences.CHAT_REGISTRATION_COMPLETE);
        LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
        return true;
    } else if (componentInfo.getPackageName() != "com.arctech.stikyhive") {
        flagNoti = true;
        return false;
    } else {
        flagNoti = false;
        return false;
    }
}

From source file:com.stikyhive.gcm.MyGcmListenerService.java

public boolean checkApp() {
    ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE);

    // get the info from the currently running task
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);

    //        ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
    //        List<ActivityManager.RunningTaskInfo> services = activityManager
    //                .getRunningTasks(Integer.MAX_VALUE);

    ComponentName componentInfo = taskInfo.get(0).topActivity;
    Log.i("Package Activity", " " + componentInfo.getPackageName());
    Log.i("Class Activity", " " + componentInfo.getClassName());
    if (componentInfo.getClassName().equalsIgnoreCase("com.stikyhive.stikyhive.StikyChatMoreActivity")) {
        Log.i(TAG, "Chat More Activity");
        StikyChatMoreActivity.flagGCM = true;
        flagNoti = false;/*w w w. j a v  a 2 s.c o  m*/
        Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(registrationComplete);
        return false;
    } else if (componentInfo.getClassName().equalsIgnoreCase("com.stikyhive.stikyhive.ChattingActivity")) {
        Log.i("TAG", componentInfo.getClass() + " ");
        Intent registrationComplete = new Intent(QuickstartPreferences.CHAT_REGISTRATION_COMPLETE);
        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(registrationComplete);
        return true;
    } else if (componentInfo.getPackageName() != "com.stikyhive.stikyhive") {
        flagNoti = true;
        return false;
    } else {
        flagNoti = false;
        return false;
    }
}