Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 13
Registered: ‎02-26-2013
My Device: blackberry curve 8520
My Carrier: 9963563582

Implement custom url schema in blackberry

Hi i am implementing the url schema in android/ios with mime type as "myapp" and the url looks like follows

 

myapp://u="ashok".......

 

when i put the same mime type for BB,the browser is not redirecting to my application

 

 

here is the BB code.

 

/*
* BrowserPlugin.java
*
* Copyright © 1998-2010 Research In Motion Ltd.
*
* Note: For the sake of simplicity, this sample application may not leverage
* resource bundles and resource strings. However, it is STRONGLY recommended
* that application developers make use of the localization features available
* within the BlackBerry development platform to ensure a seamless application
* experience across a variety of languages and geographies. For more information
* on localizing your application, please refer to the BlackBerry Java Development
* Environment Development Guide associated with this release.
*/
package com.ca.secure.mail.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;

import net.rim.device.api.browser.field.BrowserContent;
import net.rim.device.api.browser.field.BrowserContentBaseImpl;
import net.rim.device.api.browser.field.RenderingException;
import net.rim.device.api.browser.field.RenderingOptions;
import net.rim.device.api.browser.plugin.BrowserContentProvider;
import net.rim.device.api.browser.plugin.BrowserContentProviderContext;
import net.rim.device.api.browser.plugin.BrowserPageContext;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.ApplicationManagerException;
import net.rim.device.api.system.CodeModuleManager;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.VerticalFieldManager;

/**
* To test the plugin - create a file with xxxtest extension and associate that
* type with application/x-vnd.rim.xxxtest mime type on any web server.
*/
public final class BrowserPlugin extends BrowserContentProvider implements BrowserPageContext
{


private static String[] ACCEPT = {"myapp"};
String username = null;
String[] retAr = new String[0];
Hashtable htUserDet = null;
private static final int BAOS_SIZE = 1024;
private static final int BUFFER_SIZE = 64;
public static String MODULE = "MyApplication";

/**
* @see net.rim.device.api.browser.plugin.BrowserContentProvider#getAccept(net.rim.device.api.browser.field.RenderingOptions)
*/
public String[] getAccept(RenderingOptions context)
{
Logger.out("Browserplugin", "In the getAccept ");
return getSupportedMimeTypes();
}

public BrowserContent getBrowserContent(BrowserContentProviderContext ctxt) throws RenderingException {

Logger.out("Browserplugin", "Inside the getBrowserContent ");
// Create browser content
BrowserContentBaseImpl cbase = new BrowserContentBaseImpl(ctxt
.getHttpConnection().getURL(), null, ctxt
.getRenderingApplication(), ctxt.getRenderingSession()
.getRenderingOptions(), ctxt.getFlags());

String msg = "";

VerticalFieldManager vfm = new VerticalFieldManager();
LabelField lb = new LabelField();
lb.setText(msg);
vfm.add(lb);
cbase.setContent(vfm);

int modeHandle = CodeModuleManager.getModuleHandle(MODULE);
ApplicationDescriptor[] apDes = new ApplicationDescriptor[0];

if (modeHandle == 0) {
msg = MODULE + " not found";
} else {
apDes = CodeModuleManager.getApplicationDescriptors(modeHandle);
// Read parameters
byte[] bytes = null;
String str = null;

try {
InputStream is = ctxt.getInputStream();

if (is == null) {
is = ctxt.getHttpConnection().openInputStream();
}
bytes = readAndClose(is);
str = (new String(bytes)).trim();

// Launch application
ApplicationDescriptor apDes1 = new ApplicationDescriptor(apDes[0], new String[] {"browser", str});

try
{
ApplicationManager.getApplicationManager().runApplication(apDes1);
}
catch (ApplicationManagerException e)
{
msg = MODULE + " launching error";
}

}
catch (IOException e) {
msg = "Error reading data";
}
}

// Set label
lb.setText(msg);
return cbase;
}

private static byte[] read(InputStream in) throws IOException {

if (in == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream(BAOS_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
int len;

while ((len = in.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
return baos.toByteArray();
}

private static byte[] readAndClose(InputStream in) throws IOException {
try {
return read(in);
} finally {
if (in != null) {
System.out.println("Closing input stream");
in.close();
}
}
}

/**
* @see net.rim.device.api.browser.plugin.BrowserContentProvider#getSupportedMimeTypes()
*/
public String[] getSupportedMimeTypes()
{
Logger.out("Browserplugin", "In the getSupportedMimeTypes ");
return ACCEPT;
}

public boolean getPropertyWithBooleanValue(int id, boolean defaultValue) {
// TODO Auto-generated method stub
return false;
}

public int getPropertyWithIntValue(int id, int defaultValue) {
// TODO Auto-generated method stub
return 0;
}

public Object getPropertyWithObjectValue(int id, Object defaultValue) {
// TODO Auto-generated method stub
return null;
}

public String getPropertyWithStringValue(int id, String defaultValue) {
// TODO Auto-generated method stub
return null;
}

}

 

 

Please let me know how to implement the custom url schema in BB..i want to lauch the application once i visit the custom url

 

Thanks

 

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Implement custom url schema in blackberry

Sorry I have not looked at your problem in detail, just wanted to point you at HttpFilterRegistry if you hadn't already seen it.