List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Tuesday, February 5, 2013

String splitting in Blackberry

The following code will help you to split a string
String s="A,B,C,D,";
String[] n=split(s,",");
 for (int i = 0; i < n.length; i++)
{
 LabelField l=new LabelField();
 l.setText(n[i]);
add(l);
}

public static String[] split(String strString, String strDelimiter) {
        String[] strArray;
        int iOccurrences = 0;
        int iIndexOfInnerString = 0;
        int iIndexOfDelimiter = 0;
        int iCounter = 0;

        //Check for null input strings.
        if (strString == null) {
            throw new IllegalArgumentException("Input string cannot be null.");
        }
        //Check for null or empty delimiter strings.
        if (strDelimiter.length() <= 0 || strDelimiter == null) {
            throw new IllegalArgumentException("Delimeter cannot be null or empty.");
        }
        if (strString.startsWith(strDelimiter)) {
            strString = strString.substring(strDelimiter.length());
        }
        if (!strString.endsWith(strDelimiter)) {
            strString += strDelimiter;
        }
        while((iIndexOfDelimiter = strString.indexOf(strDelimiter,
               iIndexOfInnerString)) != -1) {
            iOccurrences += 1;
            iIndexOfInnerString = iIndexOfDelimiter +
                strDelimiter.length();
        }

        strArray = new String[iOccurrences];
        iIndexOfInnerString = 0;
        iIndexOfDelimiter = 0;
        while((iIndexOfDelimiter = strString.indexOf(strDelimiter,
               iIndexOfInnerString)) != -1) {

            strArray[iCounter] = strString.substring(iIndexOfInnerString,iIndexOfDelimiter);
            iIndexOfInnerString = iIndexOfDelimiter +
            strDelimiter.length();
            iCounter += 1;
        }

        return strArray;
    }
    

The answer will be - A B C D


        

Display Ads in Blackberry

The following code will display ads in blackberry. First register for blackberry adservice click here.
Banner bannerAd = new Banner(your zone id, null); bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE); //bannerAd.setTestModeFlag(true); VerticalFieldManager vfm = new VerticalFieldManager (VerticalFieldManager.NO_VERTICAL_SCROLL | VerticalFieldManager.NO_VERTICAL_SCROLLBAR | VerticalFieldManager.USE_ALL_WIDTH); HorizontalFieldManager hfm = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER | HorizontalFieldManager.FIELD_VCENTER); hfm.add(bannerAd); vfm.add(hfm); add(vfm);



        

Global Notification in Blackberry

The following code will alert a global notification-
final Bitmap image = Bitmap.getBitmapResource("your_image.png"); final Dialog screen = new Dialog(Dialog.D_OK_CANCEL, " your text to display",Dialog.OK,image,Manager.VERTICAL_SCROLL); final UiEngine ui = Ui.getUiEngine(); Application.getApplication().invokeAndWait(new Runnable() { public void run() { NotificationsManager.triggerImmediateEvent(0x222cb23a76e11c1dL, 0, null, null); ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE); } });



        

Tuesday, December 11, 2012

Blackberry In-App Payment

The Payment Service enables you to leverage a range of business models through the sale of digital goods within your applications. The Payment Service is easy to implement and provides end users with a fast, consistent, and secure purchase experience.
The Payment Service is flexible, and enables you to implement a variety of subscription and renewal options in your apps. For example, you can offer auto-renewing subscriptions, free renewals for a specified period of time, or reduced-rate renewals.

 First download and add the payment sdk jar file to your project click here.
  1. Setup a 'sandbox' account using the BlackBerry App World vendor portal
  2. Upload your app into BlackBerry App world but don't publish it, just save it and leave it in draft state
  3. Also in the vendor portal, set up your digital goods (the things available for in-app purchase)
  4. On your BlackBerry, load App World and login with your sandbox account email address.
  5. Within any screen in App World press ALT+TST and enter the SKU or ID of your test app.
  6. You can then download the test version of your app (which is not available to anyone else)
  7. Once the app is downloaded and installed you will be able to test your in app payments.
 Use the following codes for the payment-


 private PaymentEngine engine = PaymentEngine.getInstance();

 PurchaseArgumentsBuilder arguments = new PurchaseArgumentsBuilder().withDigitalGoodSku( "sku-from the appworld").withDigitalGoodName( "name of the good").withMetadata( ""name of the good") .withPurchasingAppName( "Payment Service SDK Demo" );
                   

                            try
                           {
                               Purchase purchase = engine.purchase(arguments.build());
                               Dialog.inform("Purchase of " + purchase.getMetadata()
                                   + " is successful.");
                           }
                           catch (IllegalArgumentException e)
                           {
                               Dialog.inform(e.getMessage());
                           }
                           catch (PaymentException e)
                           {
                               Dialog.inform(e.getMessage());
                           }