List of usage examples for android.app PendingIntent send
public void send(int code, @Nullable OnFinished onFinished, @Nullable Handler handler) throws CanceledException
From source file:Main.java
public static boolean sendPendingIntent(@Nullable PendingIntent pi, @NonNull Context context, @Nullable Intent intent) {/*w w w. j a v a 2s.c om*/ if (pi != null) try { pi.send(context, 0, intent); return true; } catch (PendingIntent.CanceledException e) { /* unused */ } return false; }
From source file:com.packpublishing.asynchronousandroid.chapter5.CountMsgsIntentService.java
@Override protected void onHandleIntent(Intent intent) { String phoneNumber = intent.getStringExtra(NUMBER_KEY); Cursor cursor = countMsgsFrom(phoneNumber); int numberOfMsgs = cursor.getCount(); Log.i("CountMsgsIntentService", "Number of messages found : " + numberOfMsgs); notifyUser(phoneNumber, numberOfMsgs); try {//from ww w.j a va 2 s .co m Intent result = new Intent(); result.putExtra(RESULT, numberOfMsgs); PendingIntent reply = intent.getParcelableExtra(PENDING_RESULT); reply.send(this, RESULT_CODE, result); } catch (PendingIntent.CanceledException exc) { Log.e("CountMsgsIntentService", "reply cancelled", exc); } }
From source file:net.robotmedia.billing.BillingController.java
/** * Starts the specified purchase intent with the specified activity. * /*from w w w . ja va 2 s. co m*/ * @param activity * @param purchaseIntent * purchase intent. * @param intent */ public static void startPurchaseIntent(Activity activity, PendingIntent purchaseIntent, Intent intent) { if (Compatibility.isStartIntentSenderSupported()) { // This is on Android 2.0 and beyond. The in-app buy page activity // must be on the activity stack of the application. Compatibility.startIntentSender(activity, purchaseIntent.getIntentSender(), intent); } else { // This is on Android version 1.6. The in-app buy page activity must // be on its own separate activity stack instead of on the activity // stack of the application. try { purchaseIntent.send(activity, 0 /* code */, intent); } catch (CanceledException e) { Log.e(LOG_TAG, "Error starting purchase intent", e); } } }
From source file:org.apache.cordova.SMSComposer.java
private void openSMSComposer(String message) { System.out.println("openSMSComposer"); // Intent sentIntent = new Intent(Intent.ACTION_VIEW); // sentIntent.putExtra("sms_body", message); // sentIntent.setType("vnd.android-dir/mms-sms"); // this.cordova.getActivity().startActivity(sentIntent); PendingIntent sentIntent = PendingIntent.getActivity(this.cordova.getActivity(), 0, new Intent(Intent.ACTION_VIEW), 0); Intent intent = new Intent(Intent.ACTION_VIEW); intent.putExtra("sms_body", message); intent.setType("vnd.android-dir/mms-sms"); // this.cordova.getActivity().startActivity(sentIntent); try {/*from ww w . jav a2 s. c om*/ sentIntent.send(this.cordova.getActivity().getApplicationContext(), 0, intent); } catch (CanceledException e) { System.out.println(e.getMessage()); e.printStackTrace(); } System.out.println("sent sms"); }
From source file:jp.app_mart.billing.AppmartHelper.java
/** * ??//from w ww . j av a 2 s. c o m * @param act * @param sku * @param requestCode * @param listener */ public void launchPurchaseFlow(final Activity act, final String sku, final int requestCode, final OnAppmartPurchaseFinishedListener listener) { final String itemType = "0"; checkSetupDone("launchPurchaseFlow"); (new Thread(new Runnable() { public void run() { logDebug(mContext.getString(R.string.get_information) + sku); AppmartResult result; try { Context context = mContext.getApplicationContext(); String dataEncrypted = createEncryptedData(sku, mDeveloperId, mLicenseKey, mSignatureBase64); Bundle bundleForPaymentInterface = mService.prepareForBillingService(mAppId, dataEncrypted); if (bundleForPaymentInterface == null) { logError(mContext.getString(R.string.bundle_unreachable)); result = new AppmartResult(APPMARTHELPER_GET_BUNDLE_FOR_PAYMENT_FAILED, mContext.getString(R.string.bundle_unreachable)); if (listener != null) listener.onAppmartPurchaseFinished(result, null); return; } int response = bundleForPaymentInterface.getInt("resultCode"); if (response != BILLING_RESPONSE_RESULT_OK) { logError(mContext.getString(R.string.response_code_error) + response); result = new AppmartResult(response, mContext.getString(R.string.product_not_purchasable)); if (listener != null) listener.onAppmartPurchaseFinished(result, null); return; } // ? resultKey = bundleForPaymentInterface.getString("resultKey"); PendingIntent pIntent = bundleForPaymentInterface.getParcelable("appmart_pending_intent"); mPurchaseListener = listener; mPurchasingItemType = itemType; mPurchasingSku = sku; pIntent.send(context, 0, new Intent()); } catch (RemoteException e) { logError(mContext.getString(R.string.failed_prepare_bill_service)); result = new AppmartResult(APPMARTHELPER_SEND_INTENT_FAILED, mContext.getString(R.string.failed_sending_intent)); if (listener != null) listener.onAppmartPurchaseFinished(result, null); } catch (PendingIntent.CanceledException e) { logError(mContext.getString(R.string.failed_sending_intent)); result = new AppmartResult(APPMARTHELPER_SEND_INTENT_FAILED, mContext.getString(R.string.failed_sending_intent)); if (listener != null) listener.onAppmartPurchaseFinished(result, null); } } })).start(); }
From source file:com.haibison.android.lockpattern.LockPatternFragment.java
/** * Finishes the activity with negative result ( * {@link Activity#RESULT_CANCELED}, {@link #RESULT_FAILED} or * {@link #RESULT_FORGOT_PATTERN})./*from w w w . ja va2 s .co m*/ */ private void finishWithNegativeResult(int resultCode) { if (ACTION_COMPARE_PATTERN.equals(fa.getIntent().getAction())) mIntentResult.putExtra(EXTRA_RETRY_COUNT, mRetryCount); fa.setResult(resultCode, mIntentResult); /* * ResultReceiver */ ResultReceiver receiver = fa.getIntent().getParcelableExtra(EXTRA_RESULT_RECEIVER); if (receiver != null) { Bundle resultBundle = null; if (ACTION_COMPARE_PATTERN.equals(fa.getIntent().getAction())) { resultBundle = new Bundle(); resultBundle.putInt(EXTRA_RETRY_COUNT, mRetryCount); } receiver.send(resultCode, resultBundle); } /* * PendingIntent */ PendingIntent pi = fa.getIntent().getParcelableExtra(EXTRA_PENDING_INTENT_CANCELLED); if (pi != null) { try { pi.send(getActivity(), resultCode, mIntentResult); } catch (Throwable t) { Log.e(CLASSNAME, "Error sending PendingIntent: " + pi, t); } } fa.finish(); }
From source file:com.haibison.android.lockpattern.LockPatternFragment.java
/** * Finishes activity with {@link Activity#RESULT_OK}. * * @param pattern/*from w w w .j a v a 2s . co m*/ * the pattern, if getActivity() is in mode creating pattern. In any * cases, it can be set to {@code null}. */ private void finishWithResultOk(char[] pattern) { if (ACTION_CREATE_PATTERN.equals(fa.getIntent().getAction())) mIntentResult.putExtra(EXTRA_PATTERN, pattern); else { /* * If the user was "logging in", minimum try count can not be zero. */ mIntentResult.putExtra(EXTRA_RETRY_COUNT, mRetryCount + 1); } fa.setResult(fa.RESULT_OK, mIntentResult); /* * ResultReceiver */ ResultReceiver receiver = fa.getIntent().getParcelableExtra(EXTRA_RESULT_RECEIVER); if (receiver != null) { Bundle bundle = new Bundle(); if (ACTION_CREATE_PATTERN.equals(fa.getIntent().getAction())) bundle.putCharArray(EXTRA_PATTERN, pattern); else { /* * If the user was "logging in", minimum try count can not be * zero. */ bundle.putInt(EXTRA_RETRY_COUNT, mRetryCount + 1); } receiver.send(fa.RESULT_OK, bundle); } /* * PendingIntent */ PendingIntent pi = fa.getIntent().getParcelableExtra(EXTRA_PENDING_INTENT_OK); if (pi != null) { try { pi.send(getActivity(), fa.RESULT_OK, mIntentResult); } catch (Throwable t) { Log.e(CLASSNAME, "Error sending PendingIntent: " + pi, t); } } fa.finish(); }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult sendSMS(JSONArray addressList, String text, CallbackContext callbackContext) { Log.d(LOGTAG, ACTION_SEND_SMS);//from ww w .j ava 2 s.c o m if (this.cordova.getActivity().getPackageManager().hasSystemFeature("android.hardware.telephony")) { int n; if ((n = addressList.length()) > 0) { PendingIntent sentIntent = PendingIntent.getBroadcast((Context) this.cordova.getActivity(), (int) 0, (Intent) new Intent("SENDING_SMS"), (int) 0); SmsManager sms = SmsManager.getDefault(); for (int i = 0; i < n; ++i) { String address; if ((address = addressList.optString(i)).length() <= 0) continue; sms.sendTextMessage(address, null, text, sentIntent, (PendingIntent) null); } } else { PendingIntent sentIntent = PendingIntent.getActivity((Context) this.cordova.getActivity(), (int) 0, (Intent) new Intent("android.intent.action.VIEW"), (int) 0); Intent intent = new Intent("android.intent.action.VIEW"); intent.putExtra("sms_body", text); intent.setType("vnd.android-dir/mms-sms"); try { sentIntent.send(this.cordova.getActivity().getApplicationContext(), 0, intent); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "OK")); } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "SMS is not supported")); } return null; }
From source file:edu.mit.media.funf.probe.Probe.java
/** * Send some values to each requesting pending intent * @param valuesIntent/*w w w . j a va2s . com*/ */ protected void _callback_registered(Intent valuesIntent, PendingIntent callback) { long epochTimestamp = valuesIntent.getLongExtra(TIMESTAMP, 0L); Set<PendingIntent> callbacks = new HashSet<PendingIntent>(); if (callback != null) { callbacks.add(callback); } ArrayList<Intent> requests = null; if (requestsIntent != null) { requests = requestsIntent.getParcelableArrayListExtra(INTERNAL_REQUESTS_KEY); } if (ACTION_DATA.equals(valuesIntent.getAction())) { // Send to all requesters if (requests != null && !requests.isEmpty()) { JSONObject dataSentTimes = null; try { dataSentTimes = new JSONObject( getHistoryPrefs().getString(MOST_RECENT_DATA_BY_REQUEST_KEY, "{}")); } catch (JSONException e) { Log.e(TAG, "Unable to parse data sent history."); dataSentTimes = new JSONObject(); } Parameter[] availableParameters = getAvailableParameters(); for (Intent request : requests) { PendingIntent requesterCallback = request.getParcelableExtra(CALLBACK_KEY); ArrayList<Bundle> dataRequests = Utils.getArrayList(request.getExtras(), REQUESTS_KEY); for (Bundle dataRequest : dataRequests) { String requestKey = normalizedStringRepresentation(dataRequest, getAvailableParameters()); long lastDataSentTime = dataSentTimes.optLong(requestKey); // TODO: If data request accepts passive data, but also needs data enforced on a schedule // we may need to make logic more complicated if (isDataRequestSatisfied(dataRequest, availableParameters, epochTimestamp, lastDataSentTime) || isDataRequestAcceptingPassiveData(dataRequest, availableParameters)) { callbacks.add(requesterCallback); try { dataSentTimes.put(requestKey, epochTimestamp); } catch (JSONException e) { Log.e(TAG, "Unable to store data sent time in ."); } } } } // Save the data sent times getHistoryPrefs().edit().putString(MOST_RECENT_DATA_BY_REQUEST_KEY, dataSentTimes.toString()) .putLong(MOST_RECENT_DATA_KEY, epochTimestamp).commit(); } } else { // Add all for (Intent request : requests) { PendingIntent requesterCallback = request.getParcelableExtra(CALLBACK_KEY); callbacks.add(requesterCallback); } } Log.d(TAG, "Sent probe data at " + epochTimestamp); for (PendingIntent requesterCallback : callbacks) { try { requesterCallback.send(this, 0, valuesIntent); } catch (CanceledException e) { Log.w(TAG, "Unable to send to canceled pending intent at " + epochTimestamp); Map<PendingIntent, Intent> callbacksToRequests = getCallbacksToRequests(requests); Intent request = callbacksToRequests.get(requesterCallback); if (request != null) { deadRequests.add(request); } } } updateRequests(); }