Example usage for android.content ComponentName toString

List of usage examples for android.content ComponentName toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.restcomm.app.qoslib.Utils.QosAPI.java

static public boolean isRunning(Context context, String PackageName) {
    // Get the Activity Manager
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    // Get a list of running tasks, we are only interested in the last one,
    // the top most so we give a 1 as parameter so we only get the topmost.
    List<ActivityManager.RunningTaskInfo> rtasks = manager.getRunningTasks(10000);
    // Get the info we need for comparison.
    for (ActivityManager.RunningTaskInfo task : rtasks) {
        ComponentName c = task.baseActivity;
        if (c != null && c.toString().indexOf(PackageName) >= 0)
            return true;
    }/*  w  ww  .ja v  a 2s .  c o  m*/

    //        List<ActivityManager.AppTask> tasks = manager.getAppTasks();
    //
    //        // Get the info we need for comparison.
    //        for (ActivityManager.AppTask task:tasks) {
    //            ComponentName c = task.getTaskInfo().origActivity;
    //            if (c == null && c.equals(watchActivity))
    //                return true;
    //        }

    // If not then our app is not on the foreground.
    return false;
}

From source file:io.teak.sdk.AppConfiguration.java

public AppConfiguration(@NonNull Context context) {
    // Teak App Id
    {/*from  w w  w.  j  a va  2s.c  om*/
        this.appId = Helpers.getStringResourceByName(TEAK_APP_ID, context);
        if (this.appId == null) {
            throw new RuntimeException("Failed to find R.string." + TEAK_APP_ID);
        }
    }

    // Teak API Key
    {
        this.apiKey = Helpers.getStringResourceByName(TEAK_API_KEY, context);
        if (this.apiKey == null) {
            throw new RuntimeException("Failed to find R.string." + TEAK_API_KEY);
        }
    }

    // Push Sender Id
    {
        // TODO: Check ADM vs GCM
        this.pushSenderId = Helpers.getStringResourceByName(TEAK_GCM_SENDER_ID, context);
        if (this.pushSenderId == null && Teak.isDebug) {
            Log.d(LOG_TAG, "R.string." + TEAK_GCM_SENDER_ID + " not present, push notifications disabled.");
        }
    }

    // Package Id
    {
        this.bundleId = context.getPackageName();
        if (this.bundleId == null) {
            throw new RuntimeException("Failed to get Bundle Id.");
        }
    }

    PackageManager packageManager = context.getPackageManager();
    if (packageManager == null) {
        throw new RuntimeException("Unable to get Package Manager.");
    }

    // App Version
    {
        int tempAppVersion = 0;
        try {
            tempAppVersion = packageManager.getPackageInfo(this.bundleId, 0).versionCode;
        } catch (Exception e) {
            Log.e(LOG_TAG, "Error getting App Version: " + Log.getStackTraceString(e));
        } finally {
            this.appVersion = tempAppVersion;
        }
    }

    // Get the installer package
    {
        this.installerPackage = packageManager.getInstallerPackageName(this.bundleId);
        if (this.installerPackage == null) {
            Log.e(LOG_TAG, "Installer package (Store) is null, purchase tracking disabled.");
        }
    }

    // Tell the Raven service about the app id
    try {
        Intent intent = new Intent(context, RavenService.class);
        intent.putExtra("appId", this.appId);
        ComponentName componentName = context.startService(intent);
        if (componentName == null) {
            Log.e(LOG_TAG,
                    "Unable to communicate with exception reporting service. Please add:\n\t<service android:name=\"io.teak.sdk.service.RavenService\" android:process=\":teak.raven\" android:exported=\"false\"/>\nTo the <application> section of your AndroidManifest.xml");
        } else if (Teak.isDebug) {
            Log.d(LOG_TAG,
                    "Communication with exception reporting service established: " + componentName.toString());
        }
    } catch (Exception e) {
        Log.e(LOG_TAG,
                "Error calling startService for exception reporting service: " + Log.getStackTraceString(e));
    }
}

From source file:com.actionlauncher.api.LiveWallpaperSource.java

private synchronized void publishCurrentState(final ComponentName subscriber) {
    String token = mSubscriptions.get(subscriber);
    if (TextUtils.isEmpty(token)) {
        LOGD("Not active, canceling update, id=" + mName);
        return;/* w w w  .ja  v a  2s.  c  o m*/
    }

    // Publish update
    Intent intent = new Intent(ACTION_PUBLISH_STATE).setComponent(subscriber).putExtra(EXTRA_TOKEN, token)
            .putExtra(EXTRA_STATE, (mCurrentState != null) ? mCurrentState.toBundle() : null);
    try {
        ComponentName returnedSubscriber = startService(intent);
        if (returnedSubscriber == null) {
            LOGE("Update wasn't published because subscriber no longer exists" + ", id=" + mName);
            // Unsubscribe the now-defunct subscriber
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    processSubscribe(subscriber, null);
                }
            });
        } else {
            LOGD("publishCurrentState(): successfully started service " + returnedSubscriber.toString()
                    + " with intent " + intent.toString());
        }
    } catch (SecurityException e) {
        LOGE("Couldn't publish update, id=" + mName, e);
    }
}