List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.max2idea.android.fwknop.Fwknop.java
private void startApp() { Intent i = new Intent(Intent.ACTION_RUN); i.setComponent(new ComponentName("org.connectbot", "org.connectbot.HostListActivity")); PackageManager p = this.getPackageManager(); List list = p.queryIntentActivities(i, p.COMPONENT_ENABLED_STATE_DEFAULT); if (list.isEmpty()) { Log.v("SPA", "ConnectBot is not installed"); Toast.makeText(this, "ConnectBot is not installed", Toast.LENGTH_LONG).show(); } else {//from w ww. j av a 2 s .com Log.v("SPA", "Starting connectBot"); Toast.makeText(this, "Starting ConnectBot", Toast.LENGTH_LONG); startActivity(i); } }
From source file:org.scratch.microwebserver.MicrowebserverService.java
public void connectDispatcher() { final Intent i = new Intent("org.scratch.microwebserver"); i.setComponent(new ComponentName("org.scratch.microwebserver", "org.scratch.microwebserver.RemoteDispatcherService")); dispatchConn = new ServiceConnection() { 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. disptachMessenger = new Messenger(service); // We want to monitor the service for as long as we are // connected to it. try { System.err.println("SEND SERVER HELLO"); Message msg = new Message(); msg.what = MessageTypes.MSG_SERVER_HELLO.ordinal(); msg.replyTo = mMessenger; disptachMessenger.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. //HANDLE !!! e.printStackTrace();//from w ww .j a v a 2 s. c om } // As part of the sample, tell the user what happened. //Toast.makeText(Binding.this, "remote service connected",Toast.LENGTH_SHORT).show(); } public void onServiceDisconnected(ComponentName className) { // This is called when the connection with the service has been // unexpectedly disconnected -- that is, its process crashed. disptachMessenger = null; // As part of the sample, tell the user what happened. // Toast.makeText(Binding.this, R.string.remote_service_disconnected, // Toast.LENGTH_SHORT).show(); } }; bindService(i, dispatchConn, Context.BIND_AUTO_CREATE); }
From source file:org.jsharkey.grouphome.LauncherActivity.java
public void onClick(View v) { if (!(v.getTag() instanceof EntryInfo)) return;/*from w ww . j a v a2 s. c om*/ EntryInfo info = (EntryInfo) v.getTag(); // build actual intent for launching app Intent launch = new Intent(Intent.ACTION_MAIN); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.setComponent(new ComponentName(info.resolveInfo.activityInfo.applicationInfo.packageName, info.resolveInfo.activityInfo.name)); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); try { this.startActivity(launch); } catch (Exception e) { Toast.makeText(this, "Problem trying to launch application", Toast.LENGTH_SHORT).show(); Log.e(TAG, "Problem trying to launch application", e); } }
From source file:com.kentli.cycletrack.RecordingActivity.java
private void buildAlertMessageNoGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(/*from w w w . jav a 2 s.com*/ "Your phone's GPS is disabled. CycleTracks needs GPS to determine your location.\n\nGo to System Settings now to enable GPS?") .setCancelable(false).setPositiveButton("GPS Settings...", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { final ComponentName toLaunch = new ComponentName("com.android.settings", "com.android.settings.SecuritySettings"); final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(toLaunch); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent, 0); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.cancel(); } }); final AlertDialog alert = builder.create(); alert.show(); }
From source file:com.launcher.silverfish.HomeScreenFragment.java
private void configureWidget(Intent data) { // Get the selected widget information Bundle extras = data.getExtras();// w ww .j a va2s. co m int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); if (appWidgetInfo.configure != null) { // If the widget wants to be configured then start its configuration activity Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); intent.setComponent(appWidgetInfo.configure); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); startActivityForResult(intent, REQUEST_CREATE_APPWIDGET); } else { // Otherwise simply create it createWidget(data); } }
From source file:org.opensilk.music.playback.NotificationHelper.java
/** * @param which Which {@link PendingIntent} to return * @return A {@link PendingIntent} ready to control playback *//* ww w . ja va 2 s. co m*/ private PendingIntent retreivePlaybackActions(final int which) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(mContext, PlaybackService.class); switch (which) { case 1: // Play and pause action = new Intent(PlaybackConstants.TOGGLEPAUSE_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mContext, 1, action, 0); return pendingIntent; case 2: // Skip tracks action = new Intent(PlaybackConstants.NEXT_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mContext, 2, action, 0); return pendingIntent; case 3: // Previous tracks action = new Intent(PlaybackConstants.PREVIOUS_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mContext, 3, action, 0); return pendingIntent; case 4: // Stop and collapse the notification action = new Intent(PlaybackConstants.STOP_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mContext, 4, action, 0); return pendingIntent; default: break; } return null; }
From source file:com.notepadlite.MainActivity.java
private void checkForAndroidWear() { // Notepad Plugin for Android Wear sends intent with "plugin_install_complete" extra, // in order to verify that the main Notepad app is installed correctly if (getIntent().hasExtra("plugin_install_complete")) { if (getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragmentAlt") == null) { DialogFragment wearDialog = new WearPluginDialogFragmentAlt(); wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragmentAlt"); }/*w w w . ja v a 2 s .c om*/ SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putBoolean("show_wear_dialog", false); editor.apply(); } else { boolean hasAndroidWear = false; @SuppressWarnings("unused") PackageInfo pInfo; try { pInfo = getPackageManager().getPackageInfo("com.google.android.wearable.app", 0); hasAndroidWear = true; } catch (PackageManager.NameNotFoundException e) { } if (hasAndroidWear) { try { pInfo = getPackageManager().getPackageInfo("com.notepadlite.wear", 0); Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(ComponentName .unflattenFromString("com.notepadlite.wear/com.notepadlite.wear.MobileMainActivity")); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } catch (PackageManager.NameNotFoundException e) { SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE); if (pref.getBoolean("show_wear_dialog", true) && getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragment") == null) { DialogFragment wearDialog = new WearPluginDialogFragment(); wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragment"); } } catch (ActivityNotFoundException e) { } } } }
From source file:com.vyasware.vaani.MainActivity.java
private void doOpen(String[] sentence) { System.out.println("open"); for (String word : sentence) { switch (word) { //? ??? case "?": case "facebook": //open facebook Intent fbintent = new Intent(); fbintent.setAction(Intent.ACTION_VIEW); fbintent.setData(android.net.Uri.parse("http://www.facebook.com")); startActivity(fbintent);/*from w ww. ja v a2 s .co m*/ break; case "whatsapp": case "???": //todo run whatsapp break; case "camera": case "": case "": //open camera Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); try { PackageManager pm = getPackageManager(); final ResolveInfo mInfo = pm.resolveActivity(i, 0); Intent intent = new Intent(); intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name)); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(intent); } catch (Exception e) { Log.i("open", "Unable to launch camera: " + e); } break; case "browser": case "?": // open browser Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(android.net.Uri.parse("http://www.google.com")); startActivity(intent); break; case "youtube": case "???": //run youtube Intent ytintent = new Intent(); ytintent.setAction(Intent.ACTION_VIEW); ytintent.setData(android.net.Uri.parse("http://www.youtube.com")); startActivity(ytintent); break; } } }
From source file:org.microg.gms.gcm.McsService.java
private void handleAppMessage(DataMessageStanza msg) { database.noteAppMessage(msg.category, msg.getSerializedSize()); GcmDatabase.App app = database.getApp(msg.category); Intent intent = new Intent(); intent.setAction(ACTION_C2DM_RECEIVE); intent.setPackage(msg.category);// w w w. j a v a 2 s . com intent.putExtra(EXTRA_FROM, msg.from); if (app.wakeForDelivery) { intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); } else { intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES); } if (msg.token != null) intent.putExtra(EXTRA_COLLAPSE_KEY, msg.token); for (AppData appData : msg.app_data) { intent.putExtra(appData.key, appData.value); } List<ResolveInfo> infos = getPackageManager().queryBroadcastReceivers(intent, PackageManager.GET_RESOLVED_FILTER); if (infos == null || infos.isEmpty()) { logd("No target for message, wut?"); } else { for (ResolveInfo resolveInfo : infos) { logd("Target: " + resolveInfo); Intent targetIntent = new Intent(intent); targetIntent.setComponent( new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name)); sendOrderedBroadcast(targetIntent, msg.category + ".permission.C2D_MESSAGE"); } } }
From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java
/** * Notify the mdm that provisioning has completed. When the mdm has received the intent, stop * the service and notify the {@link ProfileOwnerProvisioningActivity} so that it can finish * itself./*from ww w . j a v a 2 s . c om*/ */ private void notifyMdmAndCleanup() { // Set DPM userProvisioningState appropriately and persist mParams for use during // FinalizationActivity if necessary. mUtils.markUserProvisioningStateInitiallyDone(this, mParams); if (mParams.provisioningAction.equals(ACTION_PROVISION_MANAGED_PROFILE)) { // Set the user_setup_complete flag on the managed-profile as setup-wizard is never run // for that user. This is not relevant for other cases since // Utils.markUserProvisioningStateInitiallyDone() communicates provisioning state to // setup-wizard via DPM.setUserProvisioningState() if necessary. mUtils.markUserSetupComplete(this, mManagedProfileOrUserInfo.id); } // If profile owner provisioning was started after current user setup is completed, then we // can directly send the ACTION_PROFILE_PROVISIONING_COMPLETE broadcast to the MDM. // But if the provisioning was started as part of setup wizard flow, we signal setup-wizard // should shutdown via DPM.setUserProvisioningState(), which will result in a finalization // intent being sent to us once setup-wizard finishes. As part of the finalization intent // handling we then broadcast ACTION_PROFILE_PROVISIONING_COMPLETE. if (mUtils.isUserSetupCompleted(this)) { UserHandle managedUserHandle = new UserHandle(mManagedProfileOrUserInfo.id); // Use an ordered broadcast, so that we only finish when the mdm has received it. // Avoids a lag in the transition between provisioning and the mdm. BroadcastReceiver mdmReceivedSuccessReceiver = new MdmReceivedSuccessReceiver(mParams.accountToMigrate, mParams.deviceAdminComponentName.getPackageName()); Intent completeIntent = new Intent(ACTION_PROFILE_PROVISIONING_COMPLETE); completeIntent.setComponent(mParams.deviceAdminComponentName); completeIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES | Intent.FLAG_RECEIVER_FOREGROUND); if (mParams.adminExtrasBundle != null) { completeIntent.putExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, mParams.adminExtrasBundle); } sendOrderedBroadcastAsUser(completeIntent, managedUserHandle, null, mdmReceivedSuccessReceiver, null, Activity.RESULT_OK, null, null); ProvisionLogger.logd( "Provisioning complete broadcast has been sent to user " + managedUserHandle.getIdentifier()); } }