List of usage examples for android.content ComponentName getClassName
public @NonNull String getClassName()
From source file:com.hellofyc.base.app.AppSupportDelegate.java
public void startFragmentForResult(@NonNull Intent intent, int requestCode, @Nullable Bundle options) { ComponentName componentName = intent.getComponent(); String targetFragmentClassName = componentName.getClassName(); intent.setComponent(/* www .j av a 2s. c o m*/ new ComponentName(componentName.getPackageName(), SingleFragmentActivity.class.getName())); intent.putExtra(SingleFragmentActivity.EXTRA_FRAGMENT_CLASSNAME, targetFragmentClassName); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mActivity.startActivityForResult(intent, requestCode, options); } else { mActivity.startActivityForResult(intent, requestCode); } }
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;/* www .j a v a2 s .c om*/ 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;//from w ww .jav 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; } }
From source file:edu.umich.oasis.sandbox.SandboxContext.java
@Override public boolean bindService(Intent service, ServiceConnection conn, int flags) { ComponentName component = service.getComponent(); if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID) && component.getClassName().equals(OASISService.class.getName())) { IBinder rootBinder = mRootService.asBinder(); ComponentName oldMapping;/* w w w. j a v a 2 s .c o m*/ synchronized (mBoundServices) { oldMapping = mBoundServices.put(conn, component); } if (oldMapping == null) { conn.onServiceConnected(component, rootBinder); } return true; } return super.bindService(service, conn, flags); }
From source file:net.grayswander.rotationmanager.RotationManagerService.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event == null) { debug("Null event"); return;/*from w w w . j a v a 2 s . c om*/ } if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { String package_name; String class_name; try { package_name = event.getPackageName().toString(); class_name = event.getClassName().toString(); } catch (Exception e) { debug("Unable to get component"); return; } ComponentName componentName = new ComponentName(package_name, class_name); Log.d("Service", "Package: " + componentName.getPackageName() + " Class: " + componentName.getClassName()); ActivityInfo activityInfo = tryGetActivity(componentName); boolean isActivity = activityInfo != null; if (!isActivity) { debug("Received event with NULL activity."); return; } debug("Received app " + package_name); if (package_name.equals(this.currentPackage)) { debug("App has not been changed"); return; } debug("App has been changed"); boolean is_rotation_enabled = this.getAutoOrientationEnabled(); debug("Rotation: " + is_rotation_enabled); if (!appStartedFullScreen) { Log.d("Service", "Saving rotation settings, as fullscreen hack is inactive"); if (is_rotation_enabled != this.lastSetRotation) { debug("Setting rotation " + is_rotation_enabled + " for " + this.currentPackage); this.configuration.setRotationSetting(this.currentPackage, is_rotation_enabled); } } else { Log.d("Service", "Not saving rotation settings, as fullscreen hack is active"); } this.appStartedFullScreen = false; if (this.configuration.isForFullscreenWatcher(package_name)) { this.startFullscreenWatcher(); } else { if (this.configuration.isForFullscreenWatcher(this.currentPackage)) { this.stopFullscreenWatcher(); } } this.currentPackage = package_name; boolean app_rotation_setting = this.getAppRotationSetting(componentName); debug("Got rotation " + app_rotation_setting + " for " + package_name); if (is_rotation_enabled != app_rotation_setting) { debug("Setting rotation " + app_rotation_setting); this.setAutoOrientationEnabled(app_rotation_setting); } } }
From source file:edu.umich.flowfence.sandbox.SandboxContext.java
@Override public boolean bindService(Intent service, ServiceConnection conn, int flags) { ComponentName component = service.getComponent(); if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID) && component.getClassName().equals(FlowfenceService.class.getName())) { IBinder rootBinder = mRootService.asBinder(); ComponentName oldMapping;//from ww w. j a va2s.co m synchronized (mBoundServices) { oldMapping = mBoundServices.put(conn, component); } if (oldMapping == null) { conn.onServiceConnected(component, rootBinder); } return true; } return super.bindService(service, conn, flags); }
From source file:io.nuclei.cyto.share.PackageTargetManager.java
/** * Get a list of activities that can be shared to *//* ww w . ja va 2 s. co m*/ public void sortActivities(Context context, Intent shareIntent, List<ResolveInfo> resolveInfos) { if (mWeights == null) mWeights = context.getSharedPreferences(DEFAULT_SHARE_WEIGHTS, Context.MODE_PRIVATE); Collections.sort(resolveInfos, new Comparator<ResolveInfo>() { @Override public int compare(ResolveInfo lhs, ResolveInfo rhs) { ComponentName name1 = new ComponentName(lhs.activityInfo.packageName, lhs.activityInfo.name); ComponentName name2 = new ComponentName(rhs.activityInfo.packageName, rhs.activityInfo.name); int weight1 = mWeights.getInt(name1.getClassName(), 0); int weight2 = mWeights.getInt(name2.getClassName(), 0); if (weight1 > weight2) return -1; if (weight1 < weight2) return 1; return 0; } }); }
From source file:edu.mit.mobile.android.demomode.DemoMode.java
@Override public boolean onItemLongClick(AdapterView<?> adapter, View v, int position, long id) { switch (adapter.getId()) { case R.id.grid: { if (!mLocked) { getContentResolver().delete(ContentUris.withAppendedId(LauncherItem.CONTENT_URI, id), null, null); return true; }/*from w ww . ja va 2 s .c om*/ } break; case R.id.all_apps: { final ApplicationInfo appInfo = (ApplicationInfo) mAllApps.getItemAtPosition(position); final ContentValues cv = new ContentValues(); final ComponentName c = appInfo.intent.getComponent(); cv.put(LauncherItem.ACTIVITY_NAME, c.getClassName()); cv.put(LauncherItem.PACKAGE_NAME, c.getPackageName()); getContentResolver().insert(LauncherItem.CONTENT_URI, cv); mDrawer.close(); return true; } } return false; }
From source file:org.scratch.microwebserver.MicrowebserverActivity.java
protected void connectService() { Intent serviceIntent = new Intent(this.getApplicationContext(), MicrowebserverService.class); sconn = new ServiceConnection() { @Override//from w ww .j av a 2 s . com public void onServiceConnected(ComponentName name, IBinder service) { if (name.getClassName().equals("org.scratch.microwebserver.MicrowebserverService")) { binder = ((MicrowebserverServiceBinder) service); //global adapter ;) lea = binder.getLogEntryAdapter(); binder.registerServiceListener(MicrowebserverActivity.this); setContentView(R.layout.main); statusImage = (ImageView) findViewById(R.id.StatusImage); statusImage.setOnClickListener(MicrowebserverActivity.this); statusText = (TextView) findViewById(R.id.statusText); socketInfo = (TextView) findViewById(R.id.socketInfo); //logList=(ListView)findViewById(R.id.logList); logList.setAdapter(lea); runOnUiThread(new Runnable() { public void run() { logList.setSelection(lea.getCount()); } }); Vector<WebService> wss = new Vector<WebService>(); //add remote AND local (TODO !) wss.addAll(binder.getRegisteredRemoteWebServices()); sea = new ServiceAdapter(getPackageManager(), wss); serviceList.setAdapter(sea); //pager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new APagerAdapter()); //Bind the title indicator to the adapter TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.pagertitles); final float density = getResources().getDisplayMetrics().density; TypedValue tv = new TypedValue(); try { //fgcol (line/footer) getApplicationContext().getTheme().resolveAttribute(android.R.attr.colorActivatedHighlight, tv, true); indicator.setFooterColor(getResources().getColor(tv.resourceId)); //logList.getDivider().setColorFilter(getResources().getColor(tv.resourceId),Mode.MULTIPLY); } catch (Resources.NotFoundException rnfe) { } indicator.setFooterLineHeight(1 * density); //1dp indicator.setFooterIndicatorHeight(2 * density); //2dp indicator.setFooterIndicatorStyle(IndicatorStyle.Underline); //textcol TypedValue tv2 = new TypedValue(); try { getApplicationContext().getTheme().resolveAttribute(android.R.attr.colorActivatedHighlight, tv2, true); indicator.setTextColor(getResources().getColor(tv2.resourceId)); } catch (Resources.NotFoundException rnfe) { } //selectedtextcol TypedValue tv3 = new TypedValue(); getApplicationContext().getTheme().resolveAttribute(android.R.attr.colorForeground, tv3, true); indicator.setSelectedColor(getResources().getColor(tv3.resourceId)); indicator.setSelectedBold(true); indicator.setViewPager(pager); if (binder.isServerUp()) { runOnUiThread(new Runnable() { public void run() { statusText.setText("Started"); socketInfo.setText(Arrays.toString(binder.getListeningAdresses().toArray())); statusImage.setImageResource(R.drawable.indicator_started); } }); } else { runOnUiThread(new Runnable() { public void run() { statusText.setText("Stopped"); socketInfo.setText(""); statusImage.setImageResource(R.drawable.indicator_stopped); } }); } } } @Override public void onServiceDisconnected(ComponentName name) { if (name.getClassName().equals("comtec.tool.wifilogger.WifiLoggerService")) { // TODO: implement, do stuff here ? } } }; startService(serviceIntent); if (!bindService(serviceIntent, sconn, BIND_AUTO_CREATE)) { Log.e(PropertyNames.LOGGERNAME.toString(), "ARGH !!!!"); // TOOOOOOOAST ! or a dialog ... whatever this SHOULD not happen at // all ... } else { } }
From source file:androidx.media.SessionToken2.java
/** * Constructor for the token. You can only create token for session service or library service * to use by {@link MediaController2} or {@link MediaBrowser2}. * * @param context The context./*from www . j av a 2 s.co m*/ * @param serviceComponent The component name of the media browser service. * @param uid uid of the app. * @hide */ @RestrictTo(LIBRARY_GROUP) public SessionToken2(@NonNull Context context, @NonNull ComponentName serviceComponent, int uid) { if (serviceComponent == null) { throw new IllegalArgumentException("serviceComponent shouldn't be null"); } mComponentName = serviceComponent; mPackageName = serviceComponent.getPackageName(); mServiceName = serviceComponent.getClassName(); // Calculate uid if it's not specified. final PackageManager manager = context.getPackageManager(); if (uid < 0) { try { uid = manager.getApplicationInfo(mPackageName, 0).uid; } catch (PackageManager.NameNotFoundException e) { throw new IllegalArgumentException("Cannot find package " + mPackageName); } } mUid = uid; // Infer id and type from package name and service name String id = getSessionIdFromService(manager, MediaLibraryService2.SERVICE_INTERFACE, serviceComponent); if (id != null) { mId = id; mType = TYPE_LIBRARY_SERVICE; } else { // retry with session service mId = getSessionIdFromService(manager, MediaSessionService2.SERVICE_INTERFACE, serviceComponent); mType = TYPE_SESSION_SERVICE; } if (mId == null) { throw new IllegalArgumentException("service " + mServiceName + " doesn't implement" + " session service nor library service. Use service's full name."); } mSessionCompatToken = null; }