List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.welmo.andengine.utility.inappbilling.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. * * @param listener The listener to notify when the setup process is complete. *//*ww w . ja va 2s .c om*/ public void startSetup(final IAPurchasing 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"); if (!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.")); } } }
From source file:com.csipsimple.ui.dialpad.DialerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); Intent serviceIntent = new Intent(SipManager.INTENT_SIP_SERVICE); // Optional, but here we bundle so just ensure we are using csipsimple package serviceIntent.setPackage(activity.getPackageName()); getActivity().bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE); // timings.addSplit("Bind asked for two"); if (prefsWrapper == null) { prefsWrapper = new PreferencesWrapper(getActivity()); }//from www . j a v a 2 s. c o m if (dialFeedback == null) { dialFeedback = new DialingFeedback(getActivity(), false); } dialFeedback.resume(); }
From source file:com.yourkey.billing.util.InAppBilling.java
public boolean startServiceConnection(String itemType, String itemSku, boolean consumeActivity) { // already active if (active)/*from w w w . jav a2s . c o m*/ return (false); // set active active = true; // save item type inapp or Subs this.itemType = itemType; // save requested item SKU this.itemSku = itemSku; // buy or consume the item this.consumeActivity = consumeActivity; // create bind service intent object Intent serviceIntent = new Intent(BIND_SERVICE_INTENT); serviceIntent.setPackage(SERVICE_INTENT_PACKAGE); // make sure there is at least one service matching the intent if (applicationContext.getPackageManager().resolveService(serviceIntent, 0) == null) { // no service available to handle that Intent // call purchase listener with error message active = false; inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_UNAVAILABLE)); return (true); } // define connect and disconnect methods to handle call back from InAppBillingService serviceConnection = new ServiceConnection() { // service was disconnected call back @Override public void onServiceDisconnected(ComponentName name) { // reset serviceConnection to make sure that dispose method will not un-bind the service serviceConnection = null; active = false; // report service is disconnected to listener inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_SERVICE_DISCONNECTED)); return; } // service was connected call back @Override public void onServiceConnected(ComponentName name, IBinder service) { // process service connected serviceConnected(service); return; } }; try { // bind the service to our context and // pass the service connection object defining the connect and disconnect call back methods if (!applicationContext.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE)) { // reset serviceConnection to make sure that dispose method will not un-bind the service serviceConnection = null; active = false; inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_UNAVAILABLE)); return (true); } } // binding to in app billing service failed catch (Exception e) { // reset serviceConnection to make sure that dispose method will not un-bind the service serviceConnection = null; active = false; inAppBillingListener.inAppBillingFailure(exceptionMessage(PLAY_STORE_UNAVAILABLE, e)); return (true); } // exit while waiting for service connection return (true); }
From source file:com.test.onesignal.GenerateNotificationRunner.java
@Test @Config(shadows = { ShadowOneSignal.class }) public void shouldFireNotificationExtenderService() throws Exception { // Test that GCM receiver starts the NotificationExtenderServiceTest when it is in the AndroidManifest.xml Bundle bundle = getBaseNotifBundle(); Intent serviceIntent = new Intent(); serviceIntent.setPackage("com.onesignal.example"); serviceIntent.setAction("com.onesignal.NotificationExtender"); ResolveInfo resolveInfo = new ResolveInfo(); resolveInfo.serviceInfo = new ServiceInfo(); resolveInfo.serviceInfo.name = "com.onesignal.example.NotificationExtenderServiceTest"; RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(serviceIntent, resolveInfo); boolean ret = OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle(blankActivity, bundle); Assert.assertTrue(ret);/*from www . j a v a 2 s . c om*/ Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService(); Assert.assertEquals("com.onesignal.NotificationExtender", intent.getAction()); // Test that all options are set. NotificationExtenderServiceTest service = (NotificationExtenderServiceTest) startNotificationExtender( createInternalPayloadBundle(getBundleWithAllOptionsSet()), NotificationExtenderServiceTest.class); OSNotificationReceivedResult notificationReceived = service.notification; OSNotificationPayload notificationPayload = notificationReceived.payload; Assert.assertEquals("Test H", notificationPayload.title); Assert.assertEquals("Test B", notificationPayload.body); Assert.assertEquals("9764eaeb-10ce-45b1-a66d-8f95938aaa51", notificationPayload.notificationID); Assert.assertEquals(0, notificationPayload.lockScreenVisibility); Assert.assertEquals("FF0000FF", notificationPayload.smallIconAccentColor); Assert.assertEquals("703322744261", notificationPayload.fromProjectNumber); Assert.assertEquals("FFFFFF00", notificationPayload.ledColor); Assert.assertEquals("big_picture", notificationPayload.bigPicture); Assert.assertEquals("large_icon", notificationPayload.largeIcon); Assert.assertEquals("small_icon", notificationPayload.smallIcon); Assert.assertEquals("test_sound", notificationPayload.sound); Assert.assertEquals("You test $[notif_count] MSGs!", notificationPayload.groupMessage); Assert.assertEquals("http://google.com", notificationPayload.launchURL); Assert.assertEquals(10, notificationPayload.priority); Assert.assertEquals("a_key", notificationPayload.collapseId); Assert.assertEquals("id1", notificationPayload.actionButtons.get(0).id); Assert.assertEquals("button1", notificationPayload.actionButtons.get(0).text); Assert.assertEquals("ic_menu_share", notificationPayload.actionButtons.get(0).icon); Assert.assertEquals("id2", notificationPayload.actionButtons.get(1).id); Assert.assertEquals("button2", notificationPayload.actionButtons.get(1).text); Assert.assertEquals("ic_menu_send", notificationPayload.actionButtons.get(1).icon); Assert.assertEquals("test_image_url", notificationPayload.backgroundImageLayout.image); Assert.assertEquals("FF000000", notificationPayload.backgroundImageLayout.titleTextColor); Assert.assertEquals("FFFFFFFF", notificationPayload.backgroundImageLayout.bodyTextColor); JSONObject additionalData = notificationPayload.additionalData; Assert.assertEquals("myValue", additionalData.getString("myKey")); Assert.assertEquals("nValue", additionalData.getJSONObject("nested").getString("nKey")); Assert.assertNotSame(-1, service.notificationId); // Test a basic notification without anything special. startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle()), NotificationExtenderServiceTest.class); Assert.assertFalse(ShadowOneSignal.messages.contains("Error assigning")); // Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception. NotificationExtenderServiceTest.throwInAppCode = true; startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle("NewUUID1")), NotificationExtenderServiceTest.class); Assert.assertTrue(ShadowOneSignal.messages.contains("onNotificationProcessing throw an exception")); Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications; Assert.assertEquals(3, postedNotifs.size()); }
From source file:com.annahid.libs.artenus.internal.unified.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. * * @param listener The listener to notify when the setup process is complete. *//*from ww w .j ava 2 s. c o m*/ 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(getServiceAction()); serviceIntent.setPackage(getServiceNamespace()); if (!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.")); } } }
From source file:com.flowzr.budget.holo.export.billing.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. * * @param listener The listener to notify when the setup process is complete. *//*from w w w .j a v a 2s . com*/ public void startSetup(final OnIabSetupFinishedListener listener) { // If already set up, can't do it again. 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) { 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"); if (!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.")); } } }
From source file:com.csipsimple.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();// www.j a va 2 s . c o m }; }; t.start(); }
From source file:dynamite.zafroshops.app.MainActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); switch (id) { case R.id.action_settings: return true; case R.id.new_zop_add: addZopFragment.setVisibility();//from w ww . jav a2 s . c om FullMobileZop newZop = addZopFragment.getFullMobileZop(); ArrayList<MobileOpeningHour> moh; ArrayList<MobileZopService> ms; if (NewZopOpenings != null) { moh = new ArrayList(); for (int i = 0; i < NewZopOpenings.size(); i++) { moh.addAll(NewZopOpenings.get(i).Hours); } newZop.OpeningHours = moh; } if (NewZopServices != null) { ms = new ArrayList(); for (int i = 0; i < NewZopServices.size(); i++) { MobileZopService mzs = new MobileZopService(); mzs.Service = NewZopServices.get(i); ms.add(mzs); } newZop.Services = ms; } if (addZopFragment.ValidateNewZop(newZop)) { addZopFragment.setMessage(); addZopFragment.setVisibility(); if (PushHandler.ids == null) { PushHandler.ids = new ArrayList<>(); } PushHandler.ids.add(newZop.Name); ListenableFuture<FullMobileZop> result = MainActivity.MobileClient.invokeApi("mobileZop", newZop, FullMobileZop.class); Futures.addCallback(result, new FutureCallback<FullMobileZop>() { @Override public void onSuccess(FullMobileZop result) { SimpleDialogFragment dialog = new SimpleDialogFragment(); Bundle args = new Bundle(); if (result == null) { args.putString(SimpleDialogFragment.DIALOG_MESSAGE, getString(R.string.new_zop_failed) + "\n" + getString(R.string.new_zop_check_location)); } else if (result.id.compareTo("-1") == 0) { args.putString(SimpleDialogFragment.DIALOG_MESSAGE, getString(R.string.new_zop_failed) + "\n" + result.Name); } else { PushHandler.ids.add(result.id); args.putString(SimpleDialogFragment.DIALOG_MESSAGE, getString(R.string.new_zop_success)); NewZopOpenings.clear(); NewZopServices.clear(); addZopFragment.clearForm(null); } addZopFragment.resetVisibility(); dialog.setArguments(args); dialog.show(getSupportFragmentManager(), "new_zop_success"); } @Override public void onFailure(@NonNull Throwable t) { SimpleDialogFragment dialog = new SimpleDialogFragment(); Bundle args = new Bundle(); addZopFragment.resetVisibility(); args.putString(SimpleDialogFragment.DIALOG_MESSAGE, getString(R.string.new_zop_failed)); dialog.setArguments(args); dialog.show(getSupportFragmentManager(), "new_zop_failed"); } }); } else { addZopFragment.resetVisibility(); addZopFragment.setMessage(); } break; case R.id.menu_zop_review: if (currentZop != null) { ReviewDialogFragment dialog = new ReviewDialogFragment(); Bundle args = new Bundle(); args.putString(ReviewDialogFragment.DIALOG_ZOP_ID, zopID); dialog.setArguments(args); dialog.show(getSupportFragmentManager(), "review"); } break; case R.id.menu_zop_drive_to: if (currentZop != null && currentZop.Location != null && currentZop.Location.Latitude != null) { Uri uri = Uri.parse(String.format(Locale.US, "google.navigation:q=%f,%f", currentZop.Location.Latitude, currentZop.Location.Longitude)); Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); mapIntent.setPackage("com.google.android.apps.maps"); if (mapIntent.resolveActivity(getPackageManager()) != null) { startActivity(mapIntent); } } break; case R.id.menu_zop_call: Intent callIntent = new Intent(Intent.ACTION_CALL); if (currentZop != null && currentZop.CountryPhoneCode != null && currentZop.PhoneNumber != null && !currentZop.PhoneNumber.trim().equals("")) { callIntent.setData(Uri.parse("tel:" + currentZop.CountryPhoneCode + currentZop.PhoneNumber)); startActivity(callIntent); } break; case R.id.menu_location_refresh: getLocation(true); getAddress(true); break; case R.id.menu_zop_refresh: refresh(); break; case R.id.menu_zops_refresh: getLocation(true); getAddress(true); nextMenu(AllZopsFragment.newInstance(position, true), false, 1); break; } return super.onOptionsItemSelected(item); }
From source file:com.github.gorbin.asne.instagram.InstagramSocialNetwork.java
/** * Post photo to social network// www . j a v a 2 s.c om * @param photo photo that should be shared * @param message message that should be shared with photo * @param onPostingCompleteListener listener for posting request */ @Override public void requestPostPhoto(File photo, String message, OnPostingCompleteListener onPostingCompleteListener) { super.requestPostPhoto(photo, message, onPostingCompleteListener); String instagramPackage = "com.instagram.android"; String errorMessage = "You should install Instagram app first"; if (isPackageInstalled(instagramPackage, mSocialNetworkManager.getActivity())) { Intent normalIntent = new Intent(Intent.ACTION_SEND); normalIntent.setType("image/*"); normalIntent.setPackage(instagramPackage); File media = new File(photo.getAbsolutePath()); Uri uri = Uri.fromFile(media); normalIntent.putExtra(Intent.EXTRA_STREAM, uri); normalIntent.putExtra(Intent.EXTRA_TEXT, message); mSocialNetworkManager.getActivity().startActivity(normalIntent); } else { mLocalListeners.get(REQUEST_POST_PHOTO).onError(getID(), REQUEST_POST_PHOTO, errorMessage, null); } mLocalListeners.remove(REQUEST_POST_PHOTO); }
From source file:com.zohaltech.app.ieltsvocabulary.util.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. * * @param listener The listener to notify when the setup process is complete. *//*from w ww . ja va 2 s. co m*/ 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(App.marketAction); serviceIntent.setPackage(App.marketPackage); if (mContext.getPackageManager().queryIntentServices(serviceIntent, 0) == null) { //Log.d(TAG, "Market not found."); //MyToast.show("???? ???? ?????? ???? ?????? ??? " + App.marketName + " ?? ??? ????", Toast.LENGTH_LONG); return; } if (!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.")); } } }