List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:nirwan.cordova.plugin.printer.Printer.java
private Intent getPrintController(String appId) { String intentId = "android.intent.action.SEND"; if (appId.equals("com.rcreations.send2printer")) { intentId = "com.rcreations.send2printer.print"; } else if (appId.equals("com.dynamixsoftware.printershare")) { intentId = "android.intent.action.VIEW"; } else if (appId.equals("com.hp.android.print")) { intentId = "org.androidprinting.intent.action.PRINT"; }/*www.j a v a 2 s. c o m*/ Intent intent = new Intent(intentId); if (appId != null) intent.setPackage(appId); return intent; }
From source file:com.onesignal.TrackGooglePurchase.java
void trackIAP() { if (mServiceConn == null) { mServiceConn = new ServiceConnection() { @Override/* w ww . j av a 2s . co m*/ public void onServiceDisconnected(ComponentName name) { iapEnabled = -99; mIInAppBillingService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { try { Class<?> stubClass = Class.forName("com.android.vending.billing.IInAppBillingService$Stub"); Method asInterfaceMethod = getAsInterfaceMethod(stubClass); asInterfaceMethod.setAccessible(true); mIInAppBillingService = asInterfaceMethod.invoke(null, service); QueryBoughtItems(); } catch (Throwable t) { t.printStackTrace(); } } }; Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); appContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); } else if (mIInAppBillingService != null) QueryBoughtItems(); }
From source file:com.tingtingapps.securesms.service.KeyCachingService.java
private void handleClearKey() { Log.w("KeyCachingService", "handleClearKey()"); KeyCachingService.masterSecret = null; stopForeground(true);//from www . j a v a 2 s . c om Intent intent = new Intent(CLEAR_KEY_EVENT); intent.setPackage(getApplicationContext().getPackageName()); sendBroadcast(intent, KEY_PERMISSION); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { MessageNotifier.updateNotification(KeyCachingService.this, null); return null; } }.execute(); }
From source file:com.farmerbb.taskbar.activity.KeyboardShortcutActivity.java
@SuppressWarnings("deprecation") @Override//from w ww. j a v a2 s. co m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Perform different actions depending on how this activity was launched switch (getIntent().getAction()) { case Intent.ACTION_MAIN: Intent selector = getIntent().getSelector(); Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories(); if (categories.contains(Intent.CATEGORY_APP_MAPS)) { SharedPreferences pref = U.getSharedPreferences(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false) && isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) { U.startFreeformHack(this, false, false); } Intent startStopIntent; if (pref.getBoolean("taskbar_active", false)) startStopIntent = new Intent("com.farmerbb.taskbar.QUIT"); else startStopIntent = new Intent("com.farmerbb.taskbar.START"); startStopIntent.setPackage(BuildConfig.APPLICATION_ID); sendBroadcast(startStopIntent); } else if (categories.contains(Intent.CATEGORY_APP_CALENDAR)) U.lockDevice(this); break; case Intent.ACTION_ASSIST: if (U.isServiceRunning(this, StartMenuService.class)) { LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU")); } else { Intent intent = new Intent("com.google.android.googlequicksearchbox.TEXT_ASSIST"); if (intent.resolveActivity(getPackageManager()) == null) intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); if (intent.resolveActivity(getPackageManager()) != null) { SharedPreferences pref = U.getSharedPreferences(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false) && isInMultiWindowMode()) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); U.launchAppMaximized(getApplicationContext(), intent); } else { intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } } break; } finish(); }
From source file:cz.martykan.webtube.MenuHelper.java
@Override public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.action_web: context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl()))); return true; case R.id.action_refresh: webView.reload();//from www .j a va 2s. c o m return true; case R.id.action_home: homepageTutorial(); webView.loadUrl(sp.getString("homepage", "https://m.youtube.com/")); return true; case R.id.action_set_as_home: Snackbar.make(appWindow, context.getString(R.string.homePageSet), Snackbar.LENGTH_LONG).show(); SharedPreferences.Editor editor = sp.edit(); editor.putString("homepage", webView.getUrl()); editor.commit(); return true; case R.id.action_bookmarks: drawerLayout.openDrawer(bookmarksPanel); return true; case R.id.action_share: if (!webView.getUrl().contains("/watch")) { show_noVideo_dialog(); } else { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl()); shareIntent.setType("text/plain"); context.startActivity( Intent.createChooser(shareIntent, context.getResources().getText(R.string.share_with))); } return true; case R.id.action_cast_to_kodi: if (!webView.getUrl().contains("/watch")) { show_noVideo_dialog(); } else { try { /* The following code is based on an extract from the source code of NewPipe (v0.7.2) (https://github.com/theScrabi/NewPipe), which is also licenced under version 3 of the GNU General Public License as published by the Free Software Foundation. The copyright owner of the original code is Christian Schabesberger <chris.schabesberger@mailbox.org>. All modifications were made on 06-Jan-2016 */ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setPackage("org.xbmc.kore"); intent.setData(Uri.parse(webView.getUrl().replace("https", "http"))); context.startActivity(intent); /* End of the modified NewPipe code extract */ } catch (Exception e) { e.printStackTrace(); } } return true; case R.id.action_backgroundPlay: if (sp.getBoolean(BackgroundPlayHelper.PREF_BACKGROUND_PLAY_ENABLED, true)) { backgroundPlayHelper.disableBackgroundPlay(); item.setChecked(false); } else { backgroundPlayHelper.enableBackgroundPlay(); item.setChecked(true); } return true; case R.id.action_tor: final MenuItem cookieItem = actionMenu.getMenu().findItem(R.id.action_accept_cookies); try { if (sp.getBoolean(TorHelper.PREF_TOR_ENABLED, false)) { torHelper.torDisable(); item.setChecked(false); cookieItem.setChecked(sp.getBoolean(PREF_COOKIES_ENABLED, true)).setEnabled(true); } else { AlertDialog alert = new AlertDialog.Builder(context).create(); alert.setTitle(context.getString(R.string.enableTor) + "?"); alert.setMessage(context.getString(R.string.torWarning)); alert.setCancelable(false); alert.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.enable), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { torHelper.torEnable(); item.setChecked(true); cookieItem.setChecked(false).setEnabled(false); } }); alert.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { item.setChecked(false); } }); alert.show(); } } catch (Exception e) { Log.d("WebTube", e.getMessage()); } return true; case R.id.action_download: if (!webView.getUrl().contains("/watch")) { show_noVideo_dialog(); } else { new Downloader(context).download(webView.getUrl()); } return true; case R.id.action_accept_cookies: if (sp.getBoolean(PREF_COOKIES_ENABLED, true)) { CookieHelper.acceptCookies(webView, false); CookieHelper.deleteCookies(); item.setChecked(false); } else { CookieHelper.acceptCookies(webView, true); item.setChecked(true); } SharedPreferences.Editor spEdit = sp.edit(); spEdit.putBoolean(PREF_COOKIES_ENABLED, !sp.getBoolean(PREF_COOKIES_ENABLED, true)); spEdit.commit(); return true; } return false; }
From source file:net.olejon.spotcommander.DonateActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Allow landscape? if (!mTools.allowLandscape()) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Hide status bar? if (mTools.getDefaultSharedPreferencesBoolean("HIDE_STATUS_BAR")) getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Transition overridePendingTransition(R.anim.donate_start, R.anim.none); // Layout//from w ww . j a va 2s. c om setContentView(R.layout.activity_donate); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.donate_toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // In-app billing Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); intent.setPackage("com.android.vending"); bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); }
From source file:com.eurecalab.eureca.fragments.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_settings, container, false); reverseColor = (SwitchCompat) rootView.findViewById(R.id.reverseColor); apply = (Button) rootView.findViewById(R.id.apply); colorSpinner = (Spinner) rootView.findViewById(R.id.colorSpinner); signOutButton = (Button) rootView.findViewById(R.id.sign_out_button); loggedUser = (TextView) rootView.findViewById(R.id.logged_user); appLicense = (TextView) rootView.findViewById(R.id.app_license); upgrade = (Button) rootView.findViewById(R.id.upgrade); expiresIn = (TextView) rootView.findViewById(R.id.expires_in); parent = getActivity();// www . jav a2s . co m gs = (GlobalState) parent.getApplication(); user = gs.getAuthenticatedUser(); loggedUser.setText(user.getDisplayName()); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail().build(); mGoogleApiClient = new GoogleApiClient.Builder(parent) .enableAutoManage(parent, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso).build(); signOutButton.setOnClickListener(this); upgrade.setOnClickListener(this); updateUI(); TypedArray colorArray = getResources().obtainTypedArray(R.array.theme_colors); int[] colors = new int[colorArray.length()]; int defaultColor = ContextCompat.getColor(getActivity(), R.color.color_primary_red); for (int i = 0; i < colors.length; i++) { colors[i] = colorArray.getColor(i, defaultColor); } colorArray.recycle(); colorSpinnerAdapter = new ColorSpinnerAdapter(getActivity(), colors); colorSpinner.setAdapter(colorSpinnerAdapter); apply.setOnClickListener(this); sharedPreferences = getActivity().getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE); int color = sharedPreferences.getInt(getString(R.string.saved_color), R.color.color_primary_red); boolean reverse = sharedPreferences.getBoolean(getString(R.string.saved_reverse), false); int position = -1; for (int i = 0; i < colors.length; i++) { if (colors[i] == color) { position = i; break; } } colorSpinner.setSelection(position); reverseColor.setChecked(reverse); ServiceConnection mServiceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { mService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { mService = IInAppBillingService.Stub.asInterface(service); } }; Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); getActivity().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); return rootView; }
From source file:com.akalizakeza.apps.ishusho.activity.NewPostActivity.java
@AfterPermissionGranted(RC_CAMERA_PERMISSIONS) private void showImagePicker() { // Check for camera permissions if (!EasyPermissions.hasPermissions(this, cameraPerms)) { EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera", RC_CAMERA_PERMISSIONS, cameraPerms); return;// ww w . j av a 2 s . c om } // Choose file storage location File file = new File(getExternalCacheDir(), UUID.randomUUID().toString()); mFileUri = Uri.fromFile(file); // Camera final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(packageName, res.activityInfo.name)); intent.setPackage(packageName); intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri); cameraIntents.add(intent); } // Image Picker Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Intent chooserIntent = Intent.createChooser(pickerIntent, getString(R.string.picture_chooser_title)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()])); startActivityForResult(chooserIntent, TC_PICK_IMAGE); }
From source file:com.emotiona.study.listviewpage.SwipeMenuListViewFragment.java
private void open(ApplicationInfo item) { // open app//from www .j a va2 s . co m Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(item.packageName); List<ResolveInfo> resolveInfoList = getActivity().getPackageManager().queryIntentActivities(resolveIntent, 0); if (resolveInfoList != null && resolveInfoList.size() > 0) { ResolveInfo resolveInfo = resolveInfoList.get(0); String activityPackageName = resolveInfo.activityInfo.packageName; String className = resolveInfo.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName componentName = new ComponentName(activityPackageName, className); intent.setComponent(componentName); startActivity(intent); } }
From source file:com.parse.PushRouter.java
public synchronized boolean handlePush(String pushId, String timestamp, String channel, JSONObject data) { if (ParseTextUtils.isEmpty(pushId) || ParseTextUtils.isEmpty(timestamp)) { return false; }/* w ww.j a va2 s. com*/ if (!history.tryInsertPush(pushId, timestamp)) { return false; } // Persist the fact that we've seen this push. saveStateToDisk(); Bundle extras = new Bundle(); extras.putString(ParsePushBroadcastReceiver.KEY_PUSH_CHANNEL, channel); if (data == null) { extras.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, "{}"); } else { extras.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, data.toString()); } Intent intent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_RECEIVE); intent.putExtras(extras); // Set the package name to keep this intent within the given package. Context context = Parse.getApplicationContext(); intent.setPackage(context.getPackageName()); context.sendBroadcast(intent); return true; }