List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.csipsimple.service.SipService.java
public static Intent buildCallUiIntent(Context ctxt, SipCallSession callInfo) { // Resolve the package to handle call. if (UI_CALL_PACKAGE == null) { UI_CALL_PACKAGE = ctxt.getPackageName(); try {/* w ww .ja va2 s.co m*/ Map<String, DynActivityPlugin> callsUis = ExtraPlugins.getDynActivityPlugins(ctxt, SipManager.ACTION_SIP_CALL_UI); String preferredPackage = SipConfigManager.getPreferenceStringValue(ctxt, SipConfigManager.CALL_UI_PACKAGE, UI_CALL_PACKAGE); String packageName = null; boolean foundPref = false; for (String activity : callsUis.keySet()) { packageName = activity.split("/")[0]; if (preferredPackage.equalsIgnoreCase(packageName)) { UI_CALL_PACKAGE = packageName; foundPref = true; break; } } if (!foundPref && !TextUtils.isEmpty(packageName)) { UI_CALL_PACKAGE = packageName; } } catch (Exception e) { Log.e(THIS_FILE, "Error while resolving package", e); } } SipCallSession toSendInfo = new SipCallSession(callInfo); Intent intent = new Intent(SipManager.ACTION_SIP_CALL_UI); intent.putExtra(SipManager.EXTRA_CALL_INFO, toSendInfo); intent.setPackage(UI_CALL_PACKAGE); //?? //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP ); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; }
From source file:com.septrivium.augeo.ui.SipHome.java
private void startSipService() { Thread t = new Thread("StartSip") { public void run() { Intent serviceIntent = new Intent(SipManager.INTENT_SIP_SERVICE); // Optional, but here we bundle so just ensure we are using csipsimple package serviceIntent.setPackage(SipHome.this.getPackageName()); serviceIntent.putExtra(SipManager.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SipHome.this, SipHome.class)); startService(serviceIntent); postStartSipService();//from ww w . j a v a 2 s . c o m } ; }; t.start(); }
From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java
protected void stopService() { Log.d(Prefs.TAG, "Client stopService()"); //Intent i = new Intent(); Intent i = new Intent("com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge"); if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { i.setPackage("com.netcompss.ffmpeg4android"); }/*from w w w . j av a2 s . com*/ stopService(i); started = false; }
From source file:bulat.diet.helper_sport.utils.IabHelper.java
/** * Starts the setup process. This will start up the setup process * asynchronously. You will be notified through the listener when the setup * process is complete. This method is safe to call from a UI thread. * // w ww. j av a 2 s .c o m * @param listener * The listener to notify when the setup process is complete. */ public void startSetup(final OnIabSetupFinishedListener listener) { // If already set up, can't do it again. checkNotDisposed(); if (mSetupDone) throw new IllegalStateException("IAB helper is already set up."); // Connection to IAB service logDebug("Starting in-app billing setup."); mServiceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { logDebug("Billing service disconnected."); mService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { if (mDisposed) return; logDebug("Billing service connected."); mService = IInAppBillingService.Stub.asInterface(service); String packageName = mContext.getPackageName(); try { logDebug("Checking for in-app billing 3 support."); // check for in-app billing v3 support int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP); if (response != BILLING_RESPONSE_RESULT_OK) { if (listener != null) listener.onIabSetupFinished( new IabResult(response, "Error checking for billing v3 support.")); // if in-app purchases aren't supported, neither are // subscriptions. mSubscriptionsSupported = false; return; } logDebug("In-app billing version 3 supported for " + packageName); // check for v3 subscriptions support response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { logDebug("Subscriptions AVAILABLE."); mSubscriptionsSupported = true; } else { logDebug("Subscriptions NOT AVAILABLE. Response: " + response); } mSetupDone = true; } catch (RemoteException e) { if (listener != null) { listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION, "RemoteException while setting up in-app billing.")); } e.printStackTrace(); return; } if (listener != null) { listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful.")); } } }; Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); try { if (mContext != null && !mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { // service available to handle that Intent mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); } else { // no service available to handle that Intent if (listener != null) { listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE, "Billing service unavailable on device.")); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java
protected void bindService() { Log.d(Prefs.TAG, " bindService() called"); if (conn == null) { conn = new RemoteServiceConnection(); ///Intent i = new Intent(); Intent i = new Intent("com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge"); if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { i.setPackage("com.netcompss.ffmpeg4android"); }// w w w. j a v a 2 s. com bindService(i, conn, Context.BIND_AUTO_CREATE); Log.d(Prefs.TAG, "Client bindService()"); } else { Log.d(Prefs.TAG, " Client Cannot bind - service already bound"); //Toast.makeText(this, "Client Cannot bind - service already bound", Toast.LENGTH_SHORT).show(); } }
From source file:de.appplant.cordova.emailcomposer.EmailComposerImpl.java
/** * The intent with the containing email properties. * * @param params//ww w . j a v a 2 s . co m * The email properties like subject or body * @param ctx * The context of the application. * @return * The resulting intent. * @throws JSONException */ public Intent getDraftWithProperties(JSONObject params, Context ctx) throws JSONException { Intent mail = new Intent(Intent.ACTION_SEND_MULTIPLE); String app = params.optString("app", null); if (params.has("subject")) setSubject(params.getString("subject"), mail); if (params.has("body")) setBody(params.getString("body"), params.optBoolean("isHtml"), mail); if (params.has("to")) setRecipients(params.getJSONArray("to"), mail); if (params.has("cc")) setCcRecipients(params.getJSONArray("cc"), mail); if (params.has("bcc")) setBccRecipients(params.getJSONArray("bcc"), mail); if (params.has("attachments")) setAttachments(params.getJSONArray("attachments"), mail, ctx); if (!app.equals(MAILTO_SCHEME) && isAppInstalled(app, ctx)) { mail.setPackage(app); } mail.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return mail; }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Validate the notifications notification. *//*from ww w . j ava 2 s . co m*/ private static void validateNotifications(Context context, final Folder folder, final Account account, boolean getAttention, boolean ignoreUnobtrusiveSetting, NotificationKey key, final ContactFetcher contactFetcher) { NotificationManagerCompat nm = NotificationManagerCompat.from(context); final NotificationMap notificationMap = getNotificationMap(context); if (LogUtils.isLoggable(LOG_TAG, LogUtils.VERBOSE)) { LogUtils.i(LOG_TAG, "Validating Notification: %s mapSize: %d " + "folder: %s getAttention: %b ignoreUnobtrusive: %b", createNotificationString(notificationMap), notificationMap.size(), folder.name, getAttention, ignoreUnobtrusiveSetting); } else { LogUtils.i(LOG_TAG, "Validating Notification, mapSize: %d " + "getAttention: %b ignoreUnobtrusive: %b", notificationMap.size(), getAttention, ignoreUnobtrusiveSetting); } // The number of unread messages for this account and label. final Integer unread = notificationMap.getUnread(key); final int unreadCount = unread != null ? unread.intValue() : 0; final Integer unseen = notificationMap.getUnseen(key); int unseenCount = unseen != null ? unseen.intValue() : 0; Cursor cursor = null; try { final Uri.Builder uriBuilder = folder.conversationListUri.buildUpon(); uriBuilder.appendQueryParameter(UIProvider.SEEN_QUERY_PARAMETER, Boolean.FALSE.toString()); // Do not allow this quick check to disrupt any active network-enabled conversation // cursor. uriBuilder.appendQueryParameter(UIProvider.ConversationListQueryParameters.USE_NETWORK, Boolean.FALSE.toString()); cursor = context.getContentResolver().query(uriBuilder.build(), UIProvider.CONVERSATION_PROJECTION, null, null, null); if (cursor == null) { // This folder doesn't exist. LogUtils.i(LOG_TAG, "The cursor is null, so the specified folder probably does not exist"); clearFolderNotification(context, account, folder, false); return; } final int cursorUnseenCount = cursor.getCount(); // Make sure the unseen count matches the number of items in the cursor. But, we don't // want to overwrite a 0 unseen count that was specified in the intent if (unseenCount != 0 && unseenCount != cursorUnseenCount) { LogUtils.i(LOG_TAG, "Unseen count doesn't match cursor count. unseen: %d cursor count: %d", unseenCount, cursorUnseenCount); unseenCount = cursorUnseenCount; } // For the purpose of the notifications, the unseen count should be capped at the num of // unread conversations. if (unseenCount > unreadCount) { unseenCount = unreadCount; } final int notificationId = getNotificationId(account.getAccountManagerAccount(), folder); NotificationKey notificationKey = new NotificationKey(account, folder); if (unseenCount == 0) { LogUtils.i(LOG_TAG, "validateNotifications - cancelling account %s / folder %s", LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()), LogUtils.sanitizeName(LOG_TAG, folder.persistentId)); nm.cancel(notificationId); cancelConversationNotifications(notificationKey, nm); return; } // We now have all we need to create the notification and the pending intent PendingIntent clickIntent = null; NotificationCompat.Builder notification = new NotificationCompat.Builder(context); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); Map<Integer, NotificationBuilders> msgNotifications = new ArrayMap<Integer, NotificationBuilders>(); if (com.android.mail.utils.Utils.isRunningLOrLater()) { notification.setColor(context.getResources().getColor(R.color.notification_icon_color)); } if (unseenCount > 1) { notification.setSmallIcon(R.drawable.ic_notification_multiple_mail_24dp); } else { notification.setSmallIcon(R.drawable.ic_notification_mail_24dp); } notification.setTicker(account.getDisplayName()); notification.setVisibility(NotificationCompat.VISIBILITY_PRIVATE); notification.setCategory(NotificationCompat.CATEGORY_EMAIL); final long when; final long oldWhen = NotificationActionUtils.sNotificationTimestamps.get(notificationId); if (oldWhen != 0) { when = oldWhen; } else { when = System.currentTimeMillis(); } notification.setWhen(when); // The timestamp is now stored in the notification, so we can remove it from here NotificationActionUtils.sNotificationTimestamps.delete(notificationId); // Dispatch a CLEAR_NEW_MAIL_NOTIFICATIONS intent if the user taps the "X" next to a // notification. Also this intent gets fired when the user taps on a notification as // the AutoCancel flag has been set final Intent cancelNotificationIntent = new Intent( MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS); cancelNotificationIntent.setPackage(context.getPackageName()); cancelNotificationIntent.setData(Utils.appendVersionQueryParameter(context, folder.folderUri.fullUri)); cancelNotificationIntent.putExtra(Utils.EXTRA_ACCOUNT, account); cancelNotificationIntent.putExtra(Utils.EXTRA_FOLDER, folder); notification.setDeleteIntent( PendingIntent.getService(context, notificationId, cancelNotificationIntent, 0)); // Ensure that the notification is cleared when the user selects it notification.setAutoCancel(true); boolean eventInfoConfigured = false; final boolean isInbox = folder.folderUri.equals(account.settings.defaultInbox); final FolderPreferences folderPreferences = new FolderPreferences(context, account.getAccountId(), folder, isInbox); if (isInbox) { final AccountPreferences accountPreferences = new AccountPreferences(context, account.getAccountId()); moveNotificationSetting(accountPreferences, folderPreferences); } if (!folderPreferences.areNotificationsEnabled()) { LogUtils.i(LOG_TAG, "Notifications are disabled for this folder; not notifying"); // Don't notify return; } if (unreadCount > 0) { // How can I order this properly? if (cursor.moveToNext()) { final Intent notificationIntent; // Launch directly to the conversation, if there is only 1 unseen conversation final boolean launchConversationMode = (unseenCount == 1); if (launchConversationMode) { notificationIntent = createViewConversationIntent(context, account, folder, cursor); } else { notificationIntent = createViewConversationIntent(context, account, folder, null); } Analytics.getInstance().sendEvent("notification_create", launchConversationMode ? "conversation" : "conversation_list", folder.getTypeDescription(), unseenCount); if (notificationIntent == null) { LogUtils.e(LOG_TAG, "Null intent when building notification"); return; } clickIntent = createClickPendingIntent(context, notificationIntent); configureLatestEventInfoFromConversation(context, account, folderPreferences, notification, wearableExtender, msgNotifications, notificationId, cursor, clickIntent, notificationIntent, unreadCount, unseenCount, folder, when, contactFetcher); eventInfoConfigured = true; } } final boolean vibrate = folderPreferences.isNotificationVibrateEnabled(); final String ringtoneUri = folderPreferences.getNotificationRingtoneUri(); final boolean notifyOnce = !folderPreferences.isEveryMessageNotificationEnabled(); if (!ignoreUnobtrusiveSetting && notifyOnce) { // If the user has "unobtrusive notifications" enabled, only alert the first time // new mail is received in this account. This is the default behavior. See // bugs 2412348 and 2413490. LogUtils.d(LOG_TAG, "Setting Alert Once"); notification.setOnlyAlertOnce(true); } LogUtils.i(LOG_TAG, "Account: %s vibrate: %s", LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()), Boolean.toString(folderPreferences.isNotificationVibrateEnabled())); int defaults = 0; // Check if any current conversation notifications exist previously. Only notify if // one of them is new. boolean hasNewConversationNotification; Set<Integer> prevConversationNotifications = sConversationNotificationMap.get(notificationKey); if (prevConversationNotifications != null) { hasNewConversationNotification = false; for (Integer currentNotificationId : msgNotifications.keySet()) { if (!prevConversationNotifications.contains(currentNotificationId)) { hasNewConversationNotification = true; break; } } } else { hasNewConversationNotification = true; } LogUtils.d(LOG_TAG, "getAttention=%s,oldWhen=%s,hasNewConversationNotification=%s", getAttention, oldWhen, hasNewConversationNotification); /* * We do not want to notify if this is coming back from an Undo notification, hence the * oldWhen check. */ if (getAttention && oldWhen == 0 && hasNewConversationNotification) { final AccountPreferences accountPreferences = new AccountPreferences(context, account.getAccountId()); if (accountPreferences.areNotificationsEnabled()) { if (vibrate) { defaults |= Notification.DEFAULT_VIBRATE; } notification.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri)); LogUtils.i(LOG_TAG, "New email in %s vibrateWhen: %s, playing notification: %s", LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()), vibrate, ringtoneUri); } } // TODO(skennedy) Why do we do any of the above if we're just going to bail here? if (eventInfoConfigured) { defaults |= Notification.DEFAULT_LIGHTS; notification.setDefaults(defaults); if (oldWhen != 0) { // We do not want to display the ticker again if we are re-displaying this // notification (like from an Undo notification) notification.setTicker(null); } notification.extend(wearableExtender); // create the *public* form of the *private* notification we have been assembling final Notification publicNotification = createPublicNotification(context, account, folder, when, unseenCount, unreadCount, clickIntent); notification.setPublicVersion(publicNotification); nm.notify(notificationId, notification.build()); if (prevConversationNotifications != null) { Set<Integer> currentNotificationIds = msgNotifications.keySet(); for (Integer prevConversationNotificationId : prevConversationNotifications) { if (!currentNotificationIds.contains(prevConversationNotificationId)) { nm.cancel(prevConversationNotificationId); LogUtils.d(LOG_TAG, "canceling conversation notification %s", prevConversationNotificationId); } } } for (Map.Entry<Integer, NotificationBuilders> entry : msgNotifications.entrySet()) { NotificationBuilders builders = entry.getValue(); builders.notifBuilder.extend(builders.wearableNotifBuilder); nm.notify(entry.getKey(), builders.notifBuilder.build()); LogUtils.d(LOG_TAG, "notifying conversation notification %s", entry.getKey()); } Set<Integer> conversationNotificationIds = new HashSet<Integer>(); conversationNotificationIds.addAll(msgNotifications.keySet()); sConversationNotificationMap.put(notificationKey, conversationNotificationIds); } else { LogUtils.i(LOG_TAG, "event info not configured - not notifying"); } } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private Intent notificationIntent(final Bundle pushBundle, final String campaignId, final int requestId, final String intentAction, final Class<?> targetClass) { final Intent notificationIntent = new Intent(pinpointContext.getApplicationContext(), targetClass); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.setAction(intentAction); notificationIntent.putExtras(pushBundle); notificationIntent.putExtra(INTENT_SNS_NOTIFICATION_FROM, AWS_EVENT_TYPE_OPENED); notificationIntent.putExtra(CAMPAIGN_ID_PUSH_KEY, campaignId); notificationIntent.putExtra(REQUEST_ID, requestId); notificationIntent.setPackage(pinpointContext.getApplicationContext().getPackageName()); return notificationIntent; }
From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java
protected void startService() { if (started) { // Toast.makeText(this, "Service already started", Toast.LENGTH_SHORT).show(); } else {//from www . ja va2 s .c o m Intent i = new Intent("com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge"); if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { i.setPackage("com.netcompss.ffmpeg4android"); } PackageManager packageManager = getPackageManager(); List<ResolveInfo> services = packageManager.queryIntentServices(i, 0); Log.i(Prefs.TAG, "!!!!!!!!!!!!!!!!!!services.size(): " + services.size()); if (services.size() > 0) { ResolveInfo service = services.get(0); i.setClassName(service.serviceInfo.packageName, service.serviceInfo.name); i.setAction("com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge"); if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { i.setPackage("com.netcompss.ffmpeg4android"); } if (!invokeFileInfoServiceFlag) { i.addCategory("Base"); Log.i(Prefs.TAG, "putting Base categoty"); } else { i.addCategory("Info"); Log.i(Prefs.TAG, "putting Info categoty"); } ComponentName cn = startService(i); Log.d(Prefs.TAG, "started: " + cn.getClassName()); } started = true; Log.d(Prefs.TAG, "Client startService()"); } }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Try to notify the content to the user. * @param content reach content.//from w ww . j a v a2 s. c o m * @param replaySystemNotifications true iff system notifications must be replayed. * @throws RuntimeException if an error occurs. */ private void notifyContent(final CapptainReachContent content, boolean replaySystemNotifications) throws RuntimeException { /* Check expiry */ final long localId = content.getLocalId(); if (content.hasExpired()) { /* Delete */ deleteContent(content); return; } /* If datapush, just broadcast, can be done in parallel with another content */ final Intent intent = content.getIntent(); if (content instanceof CapptainDataPush) { /* If it's a datapush it may already be in the process of broadcasting. */ if (!mPendingDataPushes.add(localId)) return; /* Broadcast intent */ final CapptainDataPush dataPush = (CapptainDataPush) content; intent.setPackage(mContext.getPackageName()); mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { /* The last broadcast receiver to set a defined result wins (to determine which result). */ switch (getResultCode()) { case RESULT_OK: dataPush.actionContent(context); break; case RESULT_CANCELED: dataPush.exitContent(context); break; default: dataPush.dropContent(context); } /* Clean broadcast state */ mPendingDataPushes.remove(localId); } }, null, RESULT_UNDEFINED, null, null); /* Datapush processed */ return; } /* Don't notify in-app if we are already notifying in app or showing a content */ if (mState != State.IDLE && !content.isSystemNotification()) return; /* Don't process again a pending notification */ if (mPendingNotifications.contains(localId)) return; /* Not an interactive content, exit (but there is no other type left, this is just a cast guard) */ if (!(content instanceof CapptainReachInteractiveContent)) return; CapptainReachInteractiveContent iContent = (CapptainReachInteractiveContent) content; /* Don't replay system notification unless told otherwise. */ if (!replaySystemNotifications && iContent.isSystemNotification() && iContent.getNotificationLastDisplayedDate() != null && iContent.getNotificationLastDisplayedDate() > mAppLastUpdateTime) return; /* Check if the content can be notified in the current context (behavior) */ if (!iContent.canNotify(sActivityManager.getCurrentActivityAlias())) return; /* If there is a show intent */ if (intent != null) { /* Filter intent for the target package name */ filterIntent(intent); /* If the intent could not be resolved */ if (intent.getComponent() == null) { /* If there was no category */ if (intent.getCategories() == null) /* Notification cannot be done */ throw new ActivityNotFoundException(); /* Remove categories */ Collection<String> categories = new HashSet<String>(intent.getCategories()); for (String category : categories) intent.removeCategory(category); /* Try filtering again */ filterIntent(intent); /* Notification cannot be done, skip content */ if (intent.getComponent() == null) throw new ActivityNotFoundException(); } } /* Delegate notification */ Boolean notifierResult = getNotifier(content).handleNotification(iContent); /* Check if notifier rejected content notification for now */ if (Boolean.FALSE.equals(notifierResult)) /* The notifier rejected the content, nothing more to do */ return; /* Cache content if accepted, it will most likely be used again soon for the next steps. */ mContentCache.put(localId, content); /* * If notifier did not return null (e.g. returned true, meaning actually accepted the content), * we assume the notification is correctly displayed. */ if (Boolean.TRUE.equals(notifierResult)) { /* Report displayed feedback */ iContent.displayNotification(mContext); /* Track in-app content life cycle: one at a time */ if (!iContent.isSystemNotification()) mState = State.NOTIFYING_IN_APP; } /* Track pending notifications to avoid re-processing them every time we change activity. */ if (notifierResult == null) mPendingNotifications.add(localId); }