Launch urls based on different versions of java - java

I am in a situation where i need to create a simple launcher that allows me too select which web address to launch with different versions of java. I have researched several sites. Having the user change windows settings is not an option as it would generate too many support calls or user does not have priviliges. What i want is a programming way to set or change the version of java being used to launch a url. I have seen proprietary systems make launchers with a gui that allows you to change address and java version and then launch it in a browser. I am new to development and obviously having trouble understanding which techniques to use.
Will you please point me in the right direction. I am comfortable writing guis(in c# or java) I just need to know how to write the function for the launch button?
function launchbutton(url, javaversion)
{
If (javaversionselect == 1.3)
{
open url in default browser running java version 1.3
}
If (javaversionselect == 1.4)
{
open url in default browser running java version 1.4
}
If (javaversionselect == 1.5)
{
open url in default browser running java version 1.5
}
If (javaversionselect == 1.6)
{
open url in default browser running java version 1.6}
}

Bare Bones Browser Launcher will detect the java version and use the appropriate calls.
http://www.centerkey.com/java/browser/

You wan't be able to change the version of java that for example 'IE' or 'Chrome' use from withing your application, your only solutions would be to use some kind of embedded browser
jBrowser
XPCOM from Mozilla
Browse source and look on how Eclipse embedded their browser

You can write an applet that does it. Compile something like this, using javac -target 1.3:
public class Redirector
extends Applet {
#Override
public void start() {
String newURL;
Package pkg = Object.class.getPackage();
if (pkg.isCompatibleWith("1.7")) {
newURL = "java17.html";
} else if (pkg.isCompatibleWith("1.6")) {
newURL = "java16.html";
} else if (pkg.isCompatibleWith("1.5")) {
newURL = "java15.html";
} else if (pkg.isCompatibleWith("1.4")) {
newURL = "java14.html";
} else {
newURL = "java13.html";
}
try {
getAppletContext().showDocument(new URL(newURL));
} catch (MalformedURLException e) {
showStatus(e.toString());
}
}
}
If you really want let the user choose the Java version for himself, you can create UI elements in your applet for that:
public class Redirector
extends Applet
implements ActionListener {
private Choice list;
#Override
public void init() {
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
list = new Choice();
list.add("1.7");
list.add("1.6");
list.add("1.5");
list.add("1.4");
list.add("1.3");
Button button = new Button("Launch");
button.addAtionListener(Redirector.this);
add(new Label("Java version:"));
add(list);
add(button);
}
});
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void actionPeformed(ActionEvent event) {
String newURL;
String version = list.getSelectedItem();
if (version.equals("1.7")) {
newURL = "java17.html";
} else if (version.equals("1.6")) {
newURL = "java16.html";
} else if (version.equals("1.5")) {
newURL = "java15.html";
} else if (version.equals("1.4")) {
newURL = "java14.html";
} else {
newURL = "java13.html";
}
try {
getAppletContext().showDocument(new URL(newURL));
} catch (MalformedURLException e) {
showStatus(e.toString());
}
}
}

Related

Use NetBeans(Xdebug) to debug Symfony or Zend project, many variable value cannot be shown, why?

I am using NetBeans(Xdebug) to debug Symfony or Zend project, many variable value cannot be shown. For example, here we hava a class from Symfony framework, when Xdebug is debugging into this class, all the $moduleName, $actionName value cannot be shown(even add them into watches):
class sfFrontWebController extends sfWebController
{
public function dispatch()
{
try
{
sfFilter::$filterCalled = array();
$request = $this->context->getRequest();
$moduleName = $request->getParameter('module');
$actionName = $request->getParameter('action');
if (empty($moduleName) || empty($actionName))
{
throw new sfError404Exception(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).', $request->getPathInfo(), $moduleName, $actionName));
}
$this->forward($moduleName, $actionName);
}
catch (sfException $e)
{
$e->printStackTrace();
}
catch (Exception $e)
{
sfException::createFromException($e)->printStackTrace();
}
}
}
Is this because PHP xDebug is just quite crappy? It's just a crappy toy?
If using Eclipse to debug JaveEE SSH projects, can I see the value of each variable??
btw, I am using Mac, is Netbeans weaker on Mac than on Windows?

InMobi intergration in Unity game error for android

I'm trying to integrate InMobi into my unity game to show ads. I made a jar library and call needed method via JNI in unity but getting the following error:
Android Java Exception: java.lang.NoClassDefFoundError‏
My method is static because unity doesn't do Call() for me, so I can do only CallStatic().
public static void ShowInMobi(final Context context)
{
//com.google.ads.mediation.inmobi.InMobiAdapter.disableHardwareAcceleration();
//((Activity) context).runOnUiThread(new Runnable() {
// public void run() {
String CLASS_TO_LOAD ="com.inmobi.commons.InMobi";
try
{
Class<?> newClass = Class.forName(CLASS_TO_LOAD);
System.out.println("Class "+newClass+" found successfully!");
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
System.out.println("Class "+CLASS_TO_LOAD+" not found!");
}
catch (Throwable any)
{
System.out.println("Unexpected error! "+any);
}
if(interstitialInMobi==null)
{
com.inmobi.commons.InMobi.initialize((Activity) context, "my_ad_unit_id");
interstitialInMobi = new IMInterstitial((Activity) context, "my_ad_unit_id");
interstitialInMobi.loadInterstitial();
}
else
{
if (interstitialInMobi.getState() == IMInterstitial.State.READY){
interstitialInMobi.show();
interstitialInMobi.loadInterstitial();
}
}
//}
//});
Sohan from InMobi here
Looks like you are trying to use the native SDK directly in Unity. InMobi has a Unity plugin that you can use instead. The plugin acts as the mediator between the native SDK and your app.
You can check this link for further integration details.

How to force app uninstall in order to update?

I did a mistake that apparently can be solved only by uninstalling and then installing my app again.
I delivered a message to the users, but no-one seems to uninstall it.
AFAIK, if I change the certificate file, the play store won't let me upload the application, and
obviously I don't want to upload a new app.
Is there a way to force uninstall in order to update?
Thanks!
There's no killswitch to remotely force uninstalls (that'd be a security nightmare). What you can do is publish a fixed version on Google Play, and wait for users to upgrade.
I don't know if this can help you but i had the same problem. The solution for me is that i check the app version every time the user opens it and compare it with a version code stored on apache server (in a checkversion.php file).
If versions doesn't match, i show a not cancelable dialog that ask the user to go to market and download the update.
Here is an example (keep in mind that i use Volley library to handle connections):
public class UpdateManager {
private Activity ac;
private HashMap<String,String> params;
public UpdateManager(Activity ac) {
this.ac = ac;
}
public void checkForUpdates() {
Log.d("UpdateManager","checkForUpdates() - Started...");
params = new HashMap<String,String>();
params.put("request","checkforupdates");
try {
params.put("versioncode", String.valueOf(ac.getPackageManager().getPackageInfo(ac.getPackageName(), 0).versionCode));
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (Helper.isInternetAvailable(ac)) { //this is a class i made to check internet connection availability
checkAppVersion();
} else { Log.d("UpdateManager","CheckForUpdates(): Impossible to update version due to lack of connection"); }
}
private void checkAppVersion() {
Log.d("UpdateManager","checkAppVersion() - Request started...");
JsonObjectRequest req = new JsonObjectRequest("http://yourserver/checkappversion.php", new JSONObject(params),
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
if (response != null && response.has("result")) {
try {
Log.d("UpdateManager","checkAppVersion() - Request finished - Response: "+response.getString("result"));
if (response.getString("result").matches("updaterequested")) { //Update requested. Show the relative dialog
Log.d("UpdateManager","Update requested");
askUserForUpdate();
}
else if (response.getString("result").matches("current")) { //Same version. Do nothing
Log.d("UpdateManager","Version is up to date");
}
else if (response.getString("result").matches("error")) { //You can return an error message if error occurred on server
Log.d("UpdateManager","checkappversion Error - "+response.getString("error"));
}
VolleyLog.v("Response:%n %s", response.toString(4));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("UpdateManager","Volley Error - "+error.getMessage());
}
});
req.setRetryPolicy(new DefaultRetryPolicy(60000,0,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
ConnectionController.getInstance().addToRequestQueue(req);
}
public void askUserForUpdate() {
final Dialog diag = new Dialog(ac);
diag.requestWindowFeature(Window.FEATURE_NO_TITLE);
diag.setContentView(R.layout.updatemanager_requestupdate_dialog);
diag.setCancelable(false);
diag.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
TextView t = (TextView)diag.findViewById(R.id.requestupdate_dialog_main_text);
ImageView im_ok = (ImageView)diag.findViewById(R.id.requestupdate_dialog_ok);
ImageView im_canc = (ImageView)diag.findViewById(R.id.requestupdate_dialog_canc);
t.setText(ac.getResources().getString(R.string.update_manager_askuserforupdate));
im_canc.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
diag.dismiss();
ac.finish();
}
});
im_ok.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id="+ac.getPackageName()));
diag.dismiss();
ac.startActivity(intent);
ac.finish();
}
});
diag.show();
}
}
You can then use it when your main activity (or maybe login activity) starts like this:
UpdateManager updateManager = new UpdateManager(MainActivity.this); //i assume MainActicity as the calling activity
updateManager.checkForUpdates();
Obviously this has to be implemented into the application code so, the first time, you have to rely only on the user to manually upgrade it. But this can help if you have the same problem in the future.
This is an extract from my personal code so you have to rearrange it to your needings. Hope this helps someone.
Users should be able to go to Settings > Applications > Manage Applications and select the application to be removed. I've never seen a case where the application can't be removed this way, except in the case of built-in applications which require a rooted device to remove.

How to use platformRequest to call a website Url?

I am making a j2me website launcher for an url "http://www.google.com".
I am using this code:
public class LuncherMidlet extends MIDlet {
boolean Isflage;
public void startApp() {
Isflage = false;
try {
Isflage = platformRequest("http://www.google.com");
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
if(Isflage){
destroyApp(true);
notifyDestroyed();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
This code is working fine, but when I try to close the browser of mobile it shows a message for connect to server. If I say no then it again open the this j2me launcher again. It's not exiting from mobile browser. My launcher reaches in a loop.
Kindly suggest me on this issue.
When you invoke platformRequest(), it would call to native apps, and on close on browser it is browser's stuff that is being invoked. You can't change it.

showDocument() does not display new window in IE8 with Java 7/Java 6u27

I have a Java Applet that interacts with the Java Plugin to show a document (just a URL) in a named browser window:
public class TestApplet extends Applet {
#Override
public void init() {
super.init();
final JButton showButton = new JButton("Show Google!");
showButton.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
try {
getAppletContext().showDocument(new URL("http://google.com"), "Some Window Title");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
});
add(showButton);
}
}
This has worked historically but starting with Java 7 and Java 6u27, the window fails to open in Internet Explorer (tested in IE 8). If I use _blank as the window title (target) instead of Google, the window opens correctly (albeit in a new window each time).
I've tracked down this bug that was fixed for 6u27:
Vista/IE7 further showDocument focus issue with named targeted windows
Has anybody else experienced the same behaviour? Have you found a workaround (other than using "_blank")?
Edit
Updated the example. I wasn't actually using "Google" as the target, I was using "Some Window Title" (sorry!). It seems like this problem is unique to targets with spaces in the name.
It seems like this problem is unique to targets with spaces in the name.
Two possible solutions:
Replace the " " with "%20"
Don't use a space in the name of the target! (Though I thought that would be a 'no brainer'.)
Try this code, it should work.
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(info));

Categories