List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.android.documentsui.DocumentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRoots = DocumentsApplication.getRootsCache(this); setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity);//from w w w . j a v a2s . c o m final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { // backgroundDimAmount from theme isn't applied; do it manually final WindowManager.LayoutParams a = getWindow().getAttributes(); a.dimAmount = 0.6f; getWindow().setAttributes(a); getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); final int insetX = (size.x - width) / 2; final int insetY = (size.y - height) / 2; final Drawable before = getWindow().getDecorView().getBackground(); final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); getWindow().getDecorView().setBackground(after); // Dismiss when touch down in the dimmed inset area getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final float x = event.getX(); final float y = event.getY(); if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) { finish(); return true; } } return false; } }); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); mRootsContainer = findViewById(R.id.container_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); if (icicle != null) { mState = icicle.getParcelable(EXTRA_STATE); } else { buildDefaultState(); } // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { findViewById(R.id.dialog_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } if (mState.action == ACTION_CREATE) { final String mimeType = getIntent().getType(); final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); } if (mState.action == ACTION_GET_CONTENT) { final Intent moreApps = new Intent(getIntent()); moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) { RootsFragment.show(getFragmentManager(), null); } if (!mState.restored) { if (mState.action == ACTION_MANAGE) { final Uri rootUri = getIntent().getData(); new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor()); } else { new RestoreStackTask().execute(); } } else { onCurrentDirectoryChanged(ANIM_NONE); } }
From source file:com.android.car.trust.CarEnrolmentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.car_client); mOutputText = (TextView) findViewById(R.id.textfield); final Intent intent = new Intent(this, CarEnrolmentService.class); mPrefs = PreferenceManager.getDefaultSharedPreferences(this /* context */); IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_TOKEN_STATUS_RESULT); filter.addAction(ACTION_ADD_TOKEN_RESULT); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this /* context */); mLocalBroadcastManager.registerReceiver(mReceiver, filter); mStartButton = (Button) findViewById(R.id.start_button); mStartButton.setOnClickListener(new View.OnClickListener() { @Override/*from www.ja v a 2 s . c om*/ public void onClick(View v) { // binding the service will start it if not started. bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); } }); Button revokeButton = (Button) findViewById(R.id.revoke_trust_button); revokeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(CarBleTrustAgent.ACTION_REVOKE_TRUST); intent.setPackage(getPackageName()); sendBroadcast(intent); } }); }
From source file:com.tct.email.NotificationController.java
private PendingIntent createRefreshIntent(Folder folder, boolean cleanStatus, long accountId) { String packageName = mContext.getPackageName(); long boxId = -1; Mailbox outbox = Mailbox.restoreMailboxOfType(mContext, accountId, Mailbox.TYPE_OUTBOX); if (outbox != null) { boxId = outbox.mId;/*from ww w . j a v a2s. c om*/ } Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_REFRESH); clickIntent.setPackage(packageName); clickIntent.putExtra(NotificationUtils.EXTRA_NEED_CLEAN_STATUS, cleanStatus); clickIntent.putExtra(NotificationUtils.EXTRA_OUTBOX_ID, boxId); // TS: jian.xu 2015-11-26 EMAIL BUGFIX-944797 MOD_S //Note: Get truth notification id. clickIntent.putExtra(NotificationUtils.EXTRA_FAIL_NOTIFICATION_ID, getSendFailedNotificationId(accountId)); // TS: jian.xu 2015-11-26 EMAIL BUGFIX-944797 MOD_E clickIntent.setData(folder.refreshUri); // clickIntent.setData(notificationAction.mConversation.uri); PendingIntent actionIntent = PendingIntent.getService(mContext, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); return actionIntent; }
From source file:com.farmerbb.taskbar.service.TaskbarService.java
private boolean hasLauncherIntent(String packageName) { Intent intentToResolve = new Intent(Intent.ACTION_MAIN); intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER); intentToResolve.setPackage(packageName); List<ResolveInfo> ris = getPackageManager().queryIntentActivities(intentToResolve, 0); return ris != null && ris.size() > 0; }
From source file:com.tct.email.NotificationController.java
public void showStoragePermissionNotification(String pgkName) { NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext); //get the warning icon Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_warning_grey); //The Martro style only supported after android L. if (com.tct.mail.utils.Utils.isRunningLOrLater()) { notification.setColor(mContext.getResources().getColor(R.color.notification_icon_mail_orange)); }/* w w w. ja v a2s .co m*/ notification.setContentTitle(mContext.getResources().getString(R.string.sync_storage_title)); notification.setContentText(mContext.getResources().getString(R.string.sync_storage_content)); notification.setLargeIcon(icon); notification.setSmallIcon(R.drawable.ic_notification_mail_24dp); //set the content click/tap intent //it will trigger going to app permissions settings Intent gotoSettingsIntent = gotoSettingsIntent(mContext, pgkName); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, gotoSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(contentIntent); notification.setAutoCancel(true); //TS: zheng.zou 2016-3-19 EMAIL BUGFIX-1841389 ADD_S //set the action click intent. //it will never receive notification. //never ask again Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_STORAGE_NEVER_ASK_AGAIN); clickIntent.setPackage(mContext.getPackageName()); PendingIntent pendButtonIntent = PendingIntent.getService(mContext, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.notification_button, mContext.getResources().getString(R.string.notification_never_ask_again).toUpperCase(), pendButtonIntent); Notification warningNotification = notification.build(); NotificationManager nm = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE); nm.notify(EXCHANGE_NEWSTORAGE_NOTIFICATION_ID, warningNotification); }
From source file:com.tct.email.NotificationController.java
/** * Show (or update) a exchange sync new calendar notification. If tapped, the user is taken to the Exchange permission view * where he can view the exchange permission. if tap never ask again,notification will not show. *///from ww w . j a va 2 s . com public void showCalendarNotification(String packageName) { NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext); //get the warning icon Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_warning_grey); //The Martro style only supported after android L. if (com.tct.mail.utils.Utils.isRunningLOrLater()) { notification.setColor(mContext.getResources().getColor(R.color.notification_icon_mail_orange)); } notification.setContentTitle(mContext.getResources().getString(R.string.sync_calendar_title)); notification.setContentText(mContext.getResources().getString(R.string.sync_calendar_content)); notification.setLargeIcon(icon); notification.setSmallIcon(R.drawable.ic_notification_mail_24dp); notification.setAutoCancel(true);//TS: zheng.zou 2016-3-19 EMAIL BUGFIX-1841389 ADD_S //set the content click/tap intent //it will trigger going to app permissions settings Intent gotoSettingsIntent = gotoSettingsIntent(mContext, packageName); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, gotoSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(contentIntent); //set the action click intent. //it will never receive notification. //never ask again Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_CALENDAR_NEVER_ASK_AGAIN); clickIntent.setPackage(mContext.getPackageName()); PendingIntent pendButtonIntent = PendingIntent.getService(mContext, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.notification_button, mContext.getResources().getString(R.string.notification_never_ask_again).toUpperCase(), pendButtonIntent); Notification warningNotification = notification.build(); // warningNotification.flags |= Notification.FLAG_AUTO_CANCEL; // warningNotification.flags |= Notification.DEFAULT_VIBRATE; NotificationManager nm = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE); nm.notify(EXCHANGE_NEWCALENDAR_NOTIFICATION_ID, warningNotification); }
From source file:com.tct.email.NotificationController.java
/** * Show (or update) a exchange sync new contacts notification. If tapped, the user is taken to the Exchange permission view * where he can view the exchange permission. if tap never ask again,notification will not show. *///from ww w. j av a 2 s .c o m public void showContactsNotification(String packageName) { NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext); //get the warning icon Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_warning_grey); //The Martro style only supported after android L. if (com.tct.mail.utils.Utils.isRunningLOrLater()) { notification.setColor(mContext.getResources().getColor(R.color.notification_icon_mail_orange)); } notification.setContentTitle(mContext.getResources().getString(R.string.sync_contacts_title)); notification.setContentText(mContext.getResources().getString(R.string.sync_contacts_content)); notification.setLargeIcon(icon); notification.setSmallIcon(R.drawable.ic_notification_mail_24dp); notification.setAutoCancel(true);//TS: zheng.zou 2016-3-19 EMAIL BUGFIX-1841389 ADD_S //set the content click/tap intent //it will trigger going to app permissions settings Intent gotoSettingsIntent = gotoSettingsIntent(mContext, packageName); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, gotoSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(contentIntent); //set the action click intent. //it will never receive notification. //never ask again Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_CONTACTS_NEVER_ASK_AGAIN); clickIntent.setPackage(mContext.getPackageName()); PendingIntent pendButtonIntent = PendingIntent.getService(mContext, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.notification_button, mContext.getResources().getString(R.string.notification_never_ask_again).toUpperCase(), pendButtonIntent); Notification warningNotification = notification.build(); // warningNotification.flags |= Notification.FLAG_AUTO_CANCEL; // warningNotification.flags |= Notification.DEFAULT_VIBRATE; NotificationManager nm = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE); nm.notify(EXCHANGE_NEWCONTACTS_NOTIFICATION_ID, warningNotification); }
From source file:com.e2g.ecocicle.barcode.IntentIntegrator.java
/** * Initiates a scan, using the specified camera, only for a certain set of barcode types, given as strings corresponding * to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants * like {@link #PRODUCT_CODE_TYPES} for example. * * @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for * @param cameraId camera ID of the camera to use. A negative value means "no preference". * @return the {@link android.app.AlertDialog} that was shown to the user prompting them to download the app * if a prompt was needed, or null otherwise *//* w w w. j a v a 2 s . co m*/ public final AlertDialog initiateScan(Collection<String> desiredBarcodeFormats, int cameraId) { Intent intentScan = new Intent(BS_PACKAGE + ".SCAN"); intentScan.addCategory(Intent.CATEGORY_DEFAULT); // check which types of codes to scan for if (desiredBarcodeFormats != null) { // set the desired barcode types StringBuilder joinedByComma = new StringBuilder(); for (String format : desiredBarcodeFormats) { if (joinedByComma.length() > 0) { joinedByComma.append(','); } joinedByComma.append(format); } intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString()); } // check requested camera ID if (cameraId >= 0) { intentScan.putExtra("SCAN_CAMERA_ID", cameraId); } String targetAppPackage = findTargetAppPackage(intentScan); if (targetAppPackage == null) { return showDownloadDialog(); } intentScan.setPackage(targetAppPackage); intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); attachMoreExtras(intentScan); startActivityForResult(intentScan, REQUEST_CODE); return null; }
From source file:com.online.fullsail.SaveWebMedia.java
@Override protected void onPostExecute(File download) { String fileString = download.toString(); mNM.cancel(timestamp);// ww w. jav a2 s.com System.gc(); String fileName = fileString.substring(fileString.lastIndexOf('/') + 1, fileString.length()); String fileExt = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length()); File downFile = new File(externalData, fileName); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(downFile), "application/" + fileExt); List<ResolveInfo> intents = this.context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (intents == null || intents.size() == 0) { intent.setDataAndType(Uri.fromFile(downFile), "video/" + fileExt); intents = this.context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (intents == null || intents.size() == 0) { intent.setDataAndType(Uri.fromFile(downFile), "image/" + fileExt); intents = this.context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (intents == null || intents.size() == 0) { intent = new Intent(Intent.ACTION_SEARCH); if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.ECLAIR) { intent.setPackage("com.android.vending"); } intent.putExtra("query", fileExt); } } } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this.context, 0, intent, PendingIntent.FLAG_ONE_SHOT); Notification notification = null; Resources resources = this.context.getResources(); String[] mediaTypes = resources.getStringArray(R.array.media); boolean acceptedType = false; for (int i = 0; i < mediaTypes.length; i++) { if (fileExt.toLowerCase().equals(mediaTypes[i])) { acceptedType = true; } } if (acceptedType) { Bitmap preview = null; String[] videoTypes = resources.getStringArray(R.array.movFiles); for (int i = 0; i < videoTypes.length; i++) { if (fileExt.toLowerCase().equals(videoTypes[i])) { preview = getVideoFrame(fileString); } } String[] imageTypes = resources.getStringArray(R.array.movFiles); for (int i = 0; i < imageTypes.length; i++) { if (fileExt.toLowerCase().equals(imageTypes[i])) { preview = decodeBitmapFile(fileString); } } NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context); builder.setTicker(this.context.getString(R.string.notify_download_complete)) .setWhen(System.currentTimeMillis()) .setContentTitle(this.context.getString(R.string.Document_complete)) .setContentText(this.context.getString(R.string.Pdf_completed, fileName)) .setSmallIcon(R.drawable.icon).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH) .setContentIntent(contentIntent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { notification = new NotificationCompat.BigPictureStyle(builder).bigPicture(preview).build(); } else { notification = builder.build(); } } else { NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context); builder.setContentTitle(this.context.getString(R.string.Document_complete)) .setContentText(this.context.getString(R.string.Pdf_completed, fileName)) .setSmallIcon(R.drawable.icon).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH) .setContentIntent(contentIntent); notification = builder.build(); } notification.flags |= Notification.FLAG_AUTO_CANCEL; mNM.notify(timestamp, notification); }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRoots = DocumentsApplication.getRootsCache(this); virtualIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); virtualIntent.addCategory(Intent.CATEGORY_OPENABLE); virtualIntent.setType("*/*"); virtualIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity);/*from w w w . jav a 2s . c o m*/ final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { // backgroundDimAmount from theme isn't applied; do it manually final WindowManager.LayoutParams a = getWindow().getAttributes(); a.dimAmount = 0.6f; getWindow().setAttributes(a); getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); final int insetX = (size.x - width) / 2; final int insetY = (size.y - height) / 2; final Drawable before = getWindow().getDecorView().getBackground(); final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); getWindow().getDecorView().setBackground(after); // Dismiss when touch down in the dimmed inset area getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final float x = event.getX(); final float y = event.getY(); if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) { finish(); return true; } } return false; } }); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); mRootsContainer = findViewById(R.id.container_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); if (icicle != null) { mState = icicle.getParcelable(EXTRA_STATE); } else { if (DEBUG) { Log.i(TAG, "mState"); } buildDefaultState(); } // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { findViewById(R.id.dialog_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } if (mState.action == ACTION_CREATE) { final String mimeType = virtualIntent.getType(); final String title = virtualIntent.getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); } if (mState.action == ACTION_GET_CONTENT) { final Intent moreApps = new Intent(virtualIntent); moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) { RootsFragment.show(getFragmentManager(), null); } if (!mState.restored) { if (mState.action == ACTION_MANAGE) { final Uri rootUri = virtualIntent.getData(); new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor()); } else { new RestoreStackTask().execute(); } } else { onCurrentDirectoryChanged(ANIM_NONE); } }