List of usage examples for android.content ComponentName getClassName
public @NonNull String getClassName()
From source file:Main.java
/** * Checks whether the recording service is currently running. * //from w w w . j a va2 s . co m * @param ctx * the current context * @return true if the service is running, false otherwise */ public static boolean isServiceRunning(final Context ctx, final Class<?> cls) { final ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); final List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE); for (final RunningServiceInfo serviceInfo : services) { final ComponentName componentName = serviceInfo.service; final String serviceName = componentName.getClassName(); if (serviceName.equals(cls.getName())) { return true; } } return false; }
From source file:Main.java
/** * Returns Class name of top activity//from w w w . j a va 2 s .c o m * @param context Context to provide activity information * @return String representing class name of top activity */ public static String getTopActivityClassName(Context context) { ComponentName activity = getTopActivity(context); if (activity == null) { return null; } return activity.getClassName(); }
From source file:Main.java
/** * Returns Class name of base activity// w w w . j a v a 2s .c o m * @param context Context to provide activity information * @return String representing class name of base activity */ public static String getBaseActivityClassName(Context context) { ComponentName activity = getBaseActivity(context); if (activity == null) { return null; } return activity.getClassName(); }
From source file:Main.java
public static boolean isTopActivy(Context context, String activityName) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cName = am.getRunningTasks(1).size() > 0 ? am.getRunningTasks(1).get(0).topActivity : null; if (null == cName) return false; return cName.getClassName().equals(activityName); }
From source file:com.mobivery.greent.MVYBatteryManagerActivityFragment.java
public static boolean isApplicationBroughtToBackground(final Activity activity) { ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1); // Check the top Activity against the list of Activities contained in the Application's package. if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; try {//ww w . j a v a2 s . co m PackageInfo pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES); for (ActivityInfo activityInfo : pi.activities) { if (topActivity.getClassName().equals(activityInfo.name)) return false; } } catch (PackageManager.NameNotFoundException e) { return false; // Never happens. } } return true; }
From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java
private static JSONObject buildJsonIntent(Intent data) throws JSONException { JSONObject result = new JSONObject(); result.put("data", data.getDataString()); result.put("type", data.getType()); result.put("extras", build(data.getExtras())); result.put("categories", build(data.getCategories())); result.put("action", data.getAction()); ComponentName component = data.getComponent(); if (component != null) { result.put("packagename", component.getPackageName()); result.put("classname", component.getClassName()); }/*from ww w.jav a 2 s . c o m*/ result.put("flags", data.getFlags()); return result; }
From source file:com.adguard.android.commons.BrowserUtils.java
public static void openYandexBlockingOptions(Context context) { Intent intent = new Intent(); intent.setAction(YANDEX_CONTENT_BLOCKER_ACTION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { context.startActivity(intent);//ww w . ja va 2 s. c o m return; } // For samsung-type action in Yandex browser intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION); list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { ComponentName componentName = getYandexBrowser(context, SAMSUNG_CONTENT_BLOCKER_ACTION); if (componentName != null) { intent.setClassName(componentName.getPackageName(), componentName.getClassName()); } context.startActivity(intent); } }
From source file:com.android.browser.DownloadHandler.java
/** * Notify the host application a download should be done, or that * the data should be streamed if a streaming viewer is available. * @param activity Activity requesting the download. * @param url The full url to the content that should be downloaded * @param userAgent User agent of the downloading application. * @param contentDisposition Content-disposition http header, if present. * @param mimetype The mimetype of the content reported by the server * @param referer The referer associated with the downloaded url * @param privateBrowsing If the request is coming from a private browsing tab. *///from w w w . j a v a 2 s .c o m public static void onDownloadStart(Activity activity, String url, String userAgent, String contentDisposition, String mimetype, String referer, boolean privateBrowsing) { // if we're dealing wih A/V content that's not explicitly marked // for download, check if it's streamable. if (contentDisposition == null || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { // query the package manager to see if there's a registered handler // that matches. Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(url), mimetype); ResolveInfo info = activity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { ComponentName myName = activity.getComponentName(); // If we resolved to ourselves, we don't want to attempt to // load the url only to try and download it again. if (!myName.getPackageName().equals(info.activityInfo.packageName) || !myName.getClassName().equals(info.activityInfo.name)) { // someone (other than us) knows how to handle this mime // type with this scheme, don't download. try { activity.startActivity(intent); return; } catch (ActivityNotFoundException ex) { if (LOGD_ENABLED) { Log.d(LOGTAG, "activity not found for " + mimetype + " over " + Uri.parse(url).getScheme(), ex); } // Best behavior is to fall back to a download in this // case } } } } onDownloadStartNoStream(activity, url, userAgent, contentDisposition, mimetype, referer, privateBrowsing); }
From source file:androidx.media.SessionToken2.java
private static String getSessionIdFromService(PackageManager manager, String serviceInterface, ComponentName serviceComponent) { Intent serviceIntent = new Intent(serviceInterface); // Use queryIntentServices to find services with MediaLibraryService2.SERVICE_INTERFACE. // We cannot use resolveService with intent specified class name, because resolveService // ignores actions if Intent.setClassName() is specified. serviceIntent.setPackage(serviceComponent.getPackageName()); List<ResolveInfo> list = manager.queryIntentServices(serviceIntent, PackageManager.GET_META_DATA); if (list != null) { for (int i = 0; i < list.size(); i++) { ResolveInfo resolveInfo = list.get(i); if (resolveInfo == null || resolveInfo.serviceInfo == null) { continue; }/*w ww .jav a 2 s.c om*/ if (TextUtils.equals(resolveInfo.serviceInfo.name, serviceComponent.getClassName())) { return getSessionId(resolveInfo); } } } return null; }
From source file:com.example.product.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from ww w . j a v a 2 s. c om*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { Log.e(TAG, "GCM_MESSAGE_TYPE_SEND_ERROR"); //do nothing //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { Log.e(TAG, "GCM_MESSAGE_TYPE_DELETED"); //do nothing //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { //? ?? Notification? . // This loop represents the service doing some work. /* for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } */ Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. //sendNotification("Received: " + extras.toString()); //test sendNotification sendNotification(extras); Log.i(TAG, "Received: " + extras.toString()); //?? if (!isScreenOn(this)) { Log.i(TAG, "screen is off"); //test Intent popupIntent = new Intent(this, ActivityPopUp.class).putExtras(extras) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // . this.startActivity(popupIntent); } //?? else { ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runList = am.getRunningTasks(10); ComponentName name = runList.get(0).topActivity; String className = name.getClassName(); boolean isAppRunning = false; Log.i(TAG, "className ==" + className); //? ?? AcitivityPopUp ? if (className.equals("com.example.product.ActivityPopUp")) { isAppRunning = true; } //?? ? if (isAppRunning == true) { Log.i(TAG, "screen is off, but popup is on"); //test Intent popupIntent = new Intent(this, ActivityPopUp.class).putExtras(extras) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // . this.startActivity(popupIntent); // ? ? ? } //? ? ? else { // ? ? ? ? } } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }