android.content.ComponentName Java Examples
The following examples show how to use
android.content.ComponentName.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WidgetProvider.java From DongWeather with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); Log.d(TAG, "onReceive: "); if (TextUtils.equals(SKIP_COUNTY_WEATHER, intent.getAction())) { Bundle extras = intent.getExtras(); int position = extras.getInt(ListViewService.INITENT_DATA); Log.d(TAG, "onReceive: position : " + position); Intent skipIntent = new Intent(context, WeatherActivity.class); skipIntent.putExtra("skipPosition", position); skipIntent.addFlags(FLAG_ACTIVITY_NEW_TASK); context.startActivity(skipIntent); //AppWidgetManager.getInstance(context).updateAppWidget(mComponentName, mRemoteViews); } if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(intent.getAction())) { AppWidgetManager manager = AppWidgetManager.getInstance(context); int[] appWidgetId = manager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class)); if (appWidgetId.length > 0) { manager.notifyAppWidgetViewDataChanged(appWidgetId[0], R.id.widget_listview); } } }
Example #2
Source File: NotificationUtils.java From protrip with MIT License | 6 votes |
/** * Method checks if the app is in background or not */ public static boolean isAppIsInBackground(Context context) { boolean isInBackground = true; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) { List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(context.getPackageName())) { isInBackground = false; } } } } } else { List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equals(context.getPackageName())) { isInBackground = false; } } return isInBackground; }
Example #3
Source File: MainActivity.java From android-kiosk-example with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); ComponentName deviceAdmin = new ComponentName(this, AdminReceiver.class); mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); if (!mDpm.isAdminActive(deviceAdmin)) { Toast.makeText(this, getString(R.string.not_device_admin), Toast.LENGTH_SHORT).show(); } if (mDpm.isDeviceOwnerApp(getPackageName())) { mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()}); } else { Toast.makeText(this, getString(R.string.not_device_owner), Toast.LENGTH_SHORT).show(); } mDecorView = getWindow().getDecorView(); mWebView.loadUrl("http://www.vicarasolutions.com/"); }
Example #4
Source File: ColorSnifferDialog.java From Last-Launcher with GNU General Public License v3.0 | 6 votes |
private void startColorSnifferApp() { //check app android compat currently colorSniffer api=19 and this app api=14 try { Intent intent = new Intent("android.intent.action.MAIN"); //is this correct call Rui Zhao? intent.setComponent(new ComponentName("ryey.colorsniffer", "ryey.colorsniffer.FormActivity")); //currently default color is only provided by Theme: //Is it required to send default colors of apps : YES // is it required/ to send theme related data for better experience : ask for color sniffer developer // 2121= dummy value intent.putExtra(LauncherActivity.DEFAULT_COLOR_FOR_APPS, 2121); launcherActivity.startActivityForResult(intent, LauncherActivity.COLOR_SNIFFER_REQUEST); // for activity result see LauncherActivity line 509 cancel(); } catch (ActivityNotFoundException e) { //this will never happen because this option is only shown after app is installed Uri uri = Uri.parse("market://details?id=ryey.colorsniffer"); Intent i = new Intent(Intent.ACTION_VIEW, uri); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
Example #5
Source File: MainActivity.java From InviZible with GNU General Public License v3.0 | 6 votes |
private void switchHotspot() { try { ApManager apManager = new ApManager(this); if (apManager.configApState()) { checkHotspotState(); } else { Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.TetherSettings"); intent.setComponent(cn); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivityForResult(intent, CODE_IS_AP_ON); } } catch (Exception e) { Log.e(LOG_TAG, "MainActivity onOptionsItemSelected exception " + e.getMessage() + " " + e.getCause()); } }
Example #6
Source File: MainActivity.java From xpay with Apache License 2.0 | 6 votes |
private boolean isEnabled() { String str = getPackageName(); String localObject = Settings.Secure.getString(getContentResolver(), "enabled_notification_listeners"); if (!TextUtils.isEmpty(localObject)) { String[] strArr = (localObject).split(":"); int i = 0; while (i < strArr.length) { ComponentName localComponentName = ComponentName.unflattenFromString(strArr[i]); if ((localComponentName != null) && (TextUtils.equals(str, localComponentName.getPackageName()))) return true; i += 1; } } return false; }
Example #7
Source File: WakefulBroadcastReceiver.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Do a {@link android.content.Context#startService(android.content.Intent) * Context.startService}, but holding a wake lock while the service starts. * This will modify the Intent to hold an extra identifying the wake lock; * when the service receives it in {@link android.app.Service#onStartCommand * Service.onStartCommand}, it should the Intent it receives there back to * {@link #completeWakefulIntent(android.content.Intent)} in order to release * the wake lock. * * @param context The Context in which it operate. * @param intent The Intent with which to start the service, as per * {@link android.content.Context#startService(android.content.Intent) * Context.startService}. */ public static ComponentName startWakefulService(Context context, Intent intent) { synchronized (mActiveWakeLocks) { int id = mNextId; mNextId++; if (mNextId <= 0) { mNextId = 1; } intent.putExtra(EXTRA_WAKE_LOCK_ID, id); ComponentName comp = context.startService(intent); if (comp == null) { return null; } PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wake:" + comp.flattenToShortString()); wl.setReferenceCounted(false); wl.acquire(60*1000); mActiveWakeLocks.put(id, wl); return comp; } }
Example #8
Source File: QuickRow.java From LaunchTime with GNU General Public License v3.0 | 6 votes |
public void repopulate() { final List<ComponentName> quickRowOrder = db().getAppCategoryOrder(QUICK_ROW_CAT); mQuickRow.postDelayed(new Runnable() { @Override public void run() { mQuickRow.removeAllViews(); for (ComponentName actvname : quickRowOrder) { AppLauncher app = db().getApp(actvname); if (!appAlreadyHere(app)) { ViewGroup item = mMainActivity.getLauncherView(app, true); if (item != null) { GridLayout.LayoutParams lp = new GridLayout.LayoutParams(); lp.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, GridLayout.TOP); mQuickRow.addView(item, lp); } } } } }, 400); }
Example #9
Source File: ActivityManager.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
public void writeToParcel(Parcel dest, int flags) { dest.writeInt(id); dest.writeInt(stackId); ComponentName.writeToParcel(baseActivity, dest); ComponentName.writeToParcel(topActivity, dest); if (thumbnail != null) { dest.writeInt(1); thumbnail.writeToParcel(dest, 0); } else { dest.writeInt(0); } TextUtils.writeToParcel(description, dest, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); dest.writeInt(numActivities); dest.writeInt(numRunning); dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0); dest.writeInt(resizeMode); }
Example #10
Source File: MainActivity.java From AndroidDemo with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(); //设置广播的名字(设置Action) intent.setAction("com.example.broadcastcustom.myBroadCast"); //携带数据 intent.putExtra("data","Hello David"); //Android8在静态广播的使用上做了一些限制 //https://blog.csdn.net/yegshun/article/details/81232775 intent.setComponent(new ComponentName("com.example.broadcastcustom","com.example.broadcastcustom.MyBroadcastReceiver")); //发送广播(无序广播) sendBroadcast(intent); Log.e("David","Broadcast sended !"); } }); }
Example #11
Source File: Dialog.java From PreferenceFragment with Apache License 2.0 | 5 votes |
/** * This hook is called when the user signals the desire to start a search. */ public boolean onSearchRequested() { final SearchManager searchManager = (SearchManager) mContext .getSystemService(Context.SEARCH_SERVICE); // associate search with owner activity final ComponentName appName = getAssociatedActivity(); if (appName != null && searchManager.getSearchableInfo(appName) != null) { searchManager.startSearch(null, false, appName, null, false); dismiss(); return true; } else { return false; } }
Example #12
Source File: MainFragment.java From openinwa with GNU General Public License v3.0 | 5 votes |
private void openInWhatsapp() { try { Intent intent = new Intent("android.intent.action.MAIN"); intent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation")); intent.putExtra("jid", getNumber(true) + "@s.whatsapp.net"); intent.putExtra("displayname", "+" + getNumber(true)); startActivity(Intent.parseUri("whatsapp://send/?" + getNumber(false), 0)); } catch (URISyntaxException ignore) { ignore.printStackTrace(); } catch (ActivityNotFoundException e) { Snackbar.make(this.getView(), R.string.label_error_whatsapp_not_installed, Snackbar.LENGTH_LONG).show(); } }
Example #13
Source File: CBWatcherService.java From Clip-Stack with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void bindJobScheduler() { // JobScheduler for auto clean sqlite JobInfo job = new JobInfo.Builder(JOB_ID, new ComponentName(this, SyncJobService.class)) .setRequiresCharging(true) .setRequiresDeviceIdle(true) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED) .setPeriodic(24*60*60*1000) .setPersisted(true) .build(); JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.cancel(JOB_ID); jobScheduler.schedule(job); }
Example #14
Source File: ShareHelper.java From AndroidChromium with Apache License 2.0 | 5 votes |
private static ComponentName getLastShareComponentName() { SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); String packageName = preferences.getString(PACKAGE_NAME_KEY, null); String className = preferences.getString(CLASS_NAME_KEY, null); if (packageName == null || className == null) return null; return new ComponentName(packageName, className); }
Example #15
Source File: StealthMode.java From secrecy with Apache License 2.0 | 5 votes |
public static void showApp(final Context context) { ComponentName componentToDisable = new ComponentName(context.getPackageName(), LauncherActivity.class.getName()); if (context.getPackageManager() != null) context.getPackageManager() .setComponentEnabledSetting(componentToDisable, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
Example #16
Source File: AllAppsList.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
/** * Returns whether <em>apps</em> contains <em>component</em>. */ private static boolean findActivity(List<LauncherActivityInfo> apps, ComponentName component) { for (LauncherActivityInfo info : apps) { if (info.getComponentName().equals(component)) { return true; } } return false; }
Example #17
Source File: WakeLockTrampoline.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
/** * When we receive the broadcast callback we extract the required service and start it. * The framework only releases the wakelock when onReceive returns. */ @SuppressWarnings("ConstantConditions") @Override public void onReceive(final Context context, final Intent broadcastIntent) { JoH.getWakeLock(TAG, 1000); // deliberately not released final String serviceName = broadcastIntent.getStringExtra(SERVICE_PARAMETER); UserError.Log.d(TAG, "Trampoline ignition for: " + serviceName); if (serviceName == null) { UserError.Log.wtf(TAG, "Incorrectly passed pending intent with null service parameter!"); return; } final Class serviceClass = getClassFromName(serviceName); if (serviceClass == null) { UserError.Log.wtf(TAG, "Could not resolve service class for: " + serviceName); return; } final Intent serviceIntent = new Intent(context, serviceClass); final String function = broadcastIntent.getStringExtra("function"); if (function != null) serviceIntent.putExtra("function", function); ComponentName startResult; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && BuildConfig.targetSDK >= Build.VERSION_CODES.N && ForegroundServiceStarter.shouldRunCollectorInForeground()) { try { UserError.Log.d(TAG, String.format("Starting oreo foreground service: %s", serviceIntent.getComponent().getClassName())); } catch (NullPointerException e) { UserError.Log.d(TAG, "Null pointer exception in startServiceCompat"); } startResult = context.startForegroundService(serviceIntent); } else { startResult = context.startService(serviceIntent); } if (D) UserError.Log.d(TAG, "Start result: " + startResult); }
Example #18
Source File: Util.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Calls {@link Context#startForegroundService(Intent)} if {@link #SDK_INT} is 26 or higher, or * {@link Context#startService(Intent)} otherwise. * * @param context The context to call. * @param intent The intent to pass to the called method. * @return The result of the called method. */ @Nullable public static ComponentName startForegroundService(Context context, Intent intent) { if (Util.SDK_INT >= 26) { return context.startForegroundService(intent); } else { return context.startService(intent); } }
Example #19
Source File: RecordScreenActionProvider.java From SoloPi with Apache License 2.0 | 5 votes |
@Override public void onServiceDisconnected(ComponentName name) { LogUtil.d(TAG, "SimpleRecordService disconnected"); RecordScreenActionProvider provider = pvderRef.get(); if (provider != null) { provider.binder = null; } }
Example #20
Source File: CurrentTrackLayer.java From trekarta with GNU General Public License v3.0 | 5 votes |
public void onServiceConnected(ComponentName className, IBinder service) { mTrackingService = (ILocationService) service; AsyncTask.execute(() -> { mTrack.copyFrom(mTrackingService.getTrack()); mTrackingService.registerTrackingCallback(mTrackingListener); }); }
Example #21
Source File: GcmJobService.java From JobSchedulerCompat with MIT License | 5 votes |
@Override public void onServiceDisconnected(ComponentName name) { // Should never happen as it's the same process. binder = null; if (connections.get(jobId) == this) { stopJob(this, false, false); } }
Example #22
Source File: MainActivity.java From GNSS_Compare with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { if(!mGnssCoreBound) { gnssCoreBinder = (GnssCoreService.GnssCoreBinder) service; mGnssCoreBound = true; gnssCoreBinder.addObserver(calculationModuleObserver); gnssCoreBinder.assignUserNotifier(userNotifierHandler); } }
Example #23
Source File: ContactChooserTargetService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@Override public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) { final ArrayList<ChooserTarget> chooserTargets = new ArrayList<>(); if (!EventReceiver.hasEnabledAccounts(this)) { return chooserTargets; } final Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction("contact_chooser"); Compatibility.startService(this, intent); bindService(intent, this, Context.BIND_AUTO_CREATE); try { waitForService(); final ArrayList<Conversation> conversations = new ArrayList<>(); if (!mXmppConnectionService.areMessagesInitialized()) { return chooserTargets; } mXmppConnectionService.populateWithOrderedConversations(conversations, textOnly(matchedFilter)); final ComponentName componentName = new ComponentName(this, ConversationsActivity.class); final int pixel = AvatarService.getSystemUiAvatarSize(this); for (Conversation conversation : conversations) { if (conversation.sentMessagesCount() == 0) { continue; } final String name = conversation.getName().toString(); final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel)); final float score = 1 - (1.0f / MAX_TARGETS) * chooserTargets.size(); final Bundle extras = new Bundle(); extras.putString(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid()); chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras)); if (chooserTargets.size() >= MAX_TARGETS) { break; } } } catch (InterruptedException e) { } unbindService(this); return chooserTargets; }
Example #24
Source File: QRShowActivity.java From meshenger-android with GNU General Public License v3.0 | 5 votes |
@Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { this.binder = (MainService.MainBinder) iBinder; try { generateQR(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); finish(); } }
Example #25
Source File: ShareServiceImpl.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void share(String title, String text, Url url, final ShareResponse callback) { RecordHistogram.recordEnumeratedHistogram("WebShare.ApiCount", WEBSHARE_METHOD_SHARE, WEBSHARE_METHOD_COUNT); if (mActivity == null) { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_UNKNOWN_FAILURE, WEBSHARE_OUTCOME_COUNT); callback.call(ShareError.INTERNAL_ERROR); return; } ShareHelper.TargetChosenCallback innerCallback = new ShareHelper.TargetChosenCallback() { @Override public void onTargetChosen(ComponentName chosenComponent) { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_SUCCESS, WEBSHARE_OUTCOME_COUNT); callback.call(ShareError.OK); } @Override public void onCancel() { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_CANCELED, WEBSHARE_OUTCOME_COUNT); callback.call(ShareError.CANCELED); } }; ShareHelper.share(false, false, mActivity, title, text, url.url, null, null, innerCallback); }
Example #26
Source File: Workspace.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
void updateUnvailableItemsInCellLayout(CellLayout parent, ArrayList<String> packages) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages); ViewGroup layout = parent.getShortcutsAndWidgets(); int childCount = layout.getChildCount(); for (int i = 0; i < childCount; ++i) { View view = layout.getChildAt(i); if (view instanceof BubbleTextView) { ItemInfo info = (ItemInfo) view.getTag(); if (info instanceof ShortcutInfo) { Intent intent = info.getIntent(); ComponentName cn = intent != null ? intent.getComponent() : null; if (cn != null && packageNames.contains(cn.getPackageName())) { ShortcutInfo shortcut = (ShortcutInfo) info; if (shortcut.isDisabled == 0) { shortcut.isDisabled = 1; ((BubbleTextView) view) .applyFromShortcutInfo(shortcut, mIconCache, true); } } } } else if (view instanceof FolderIcon) { final Folder folder = ((FolderIcon)view).getFolder(); final FolderPagedView folderPagedView = (FolderPagedView)folder.getContent(); final int N = folderPagedView.getItemCount(); for (int page = 0; page < N; page++) { final CellLayout cellLayout = folderPagedView.getPageAt(page); if (cellLayout != null) { updateUnvailableItemsInCellLayout(cellLayout, packages); } } folder.invalidate(); } } }
Example #27
Source File: MainActivity.java From android-performance with MIT License | 5 votes |
/** * 演示JobScheduler的使用 */ private void startJobScheduler() { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); JobInfo.Builder builder = new JobInfo.Builder(1, new ComponentName(getPackageName(), JobSchedulerService.class.getName())); builder.setRequiresCharging(true) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); jobScheduler.schedule(builder.build()); } }
Example #28
Source File: MessengerServiceActivities.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onServiceConnected(ComponentName className, IBinder service) { // This is called when the connection with the service has been // established, giving us the service object we can use to // interact with the service. We are communicating with our // service through an IDL interface, so get a client-side // representation of that from the raw service object. mService = new Messenger(service); mCallbackText.setText("Attached."); // We want to monitor the service for as long as we are // connected to it. try { Message msg = Message.obtain(null, MessengerService.MSG_REGISTER_CLIENT); msg.replyTo = mMessenger; mService.send(msg); // Give it some value as an example. msg = Message.obtain(null, MessengerService.MSG_SET_VALUE, this.hashCode(), 0); mService.send(msg); } catch (RemoteException e) { // In this case the service has crashed before we could even // do anything with it; we can count on soon being // disconnected (and then reconnected if it can be restarted) // so there is no need to do anything here. } // As part of the sample, tell the user what happened. Toast.makeText(Binding.this, R.string.remote_service_connected, Toast.LENGTH_SHORT).show(); }
Example #29
Source File: PackageManagerUtil.java From BaseProject with Apache License 2.0 | 5 votes |
/** * 判断某个指定的包名的app是否在前台 * 判断依据为:在top(前台) * @deprecated 在Android 5.1之后是判断不出来的 * @param context * @param classPackageName app 包名 * @return true:在前台; false: 在非前台 */ @Deprecated public static boolean isAppActivitysForeground(Context context, String classPackageName) { ComponentName[] topAndBaseActivities = getAppTopAndBaseActivitys(context); if (topAndBaseActivities != null && topAndBaseActivities.length > 0) { ComponentName topComponentName = topAndBaseActivities[0]; if (topComponentName != null) { String topAppPackageName = topComponentName.getPackageName(); if (classPackageName.equals(topAppPackageName)) {//在前台 return true; } } } return false; }
Example #30
Source File: ServiceBinder.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void onServiceDisconnected(ComponentName serviceName) { logger.fine("onServiceDisconnected: %s", serviceClass); synchronized (lock) { serviceInstance = null; } }