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.
Related
Hey guys i am beginner in Java programming and i am making a DiscordBot for my Discord server. Code is all right i was following the tutorial but when i try to start the program i get this error:
"java.lang.ClassNotFoundException: org.eclipse.jetty.util.log.Logger"
My code looks like this:
public static final IDiscordClient bot = createClient("your_token", true);
public static void main(String args[]) {
System.out.println(bot.getApplicationClientID());
}
public static IDiscordClient createClient(String token, boolean login)
{
ClientBuilder clientBuilder = new ClientBuilder();
clientBuilder.withToken(token);
try
{
if (login)
{
return clientBuilder.login();
}
else
{
return clientBuilder.build();
}
}
catch (DiscordException e)
{
e.printStackTrace();
return null;
}
}
Any ideas how to fix this? Thanks in advance.
Ok guys i am idiot i just downloaded lightweight jar that didnt include everything i needed. I downloaded full jar file and its ok now.
I am trying to create a bot using PircBotX, however I am unable to even get started making it. Using just the basic example code, I am unable to get the connect() method to work, it always give the error at compile mentioned in the title. Here is the code I am using:
import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;
public class MyBot {
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration.Builder()
.setName("PircBotX") //Set the nick of the bot. CHANGE IN YOUR CODE
.setLogin("LQ") //login part of hostmask, eg name:login#host
.setAutoNickChange(true) //Automatically change nick when the current one is in use
.setCapEnabled(true) //Enable CAP features
.setServerHostname("irc.freenode.net")
.addAutoJoinChannel("#pircbotx") //Join the official #pircbotx channel
.buildConfiguration();
PircBotX bot = new PircBotX(configuration);
//Connect to server
try {
bot.connect();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
The error occurs with the line bot.connect();
PircBotX can be found at its Google Code page: https://code.google.com/p/pircbotx/
On the docs, there is a method called startBot(), should that be used instead?
void startBot() Start the bot by connecting to the server.
import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;
public class MyBot {
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration.Builder()
.setName("PircBotX") //Set the nick of the bot. CHANGE IN YOUR CODE
.setLogin("LQ") //login part of hostmask, eg name:login#host
.setAutoNickChange(true) //Automatically change nick when the current one is in use
.setCapEnabled(true) //Enable CAP features
.setServerHostname("irc.freenode.net")
.addAutoJoinChannel("#pircbotx") //Join the official #pircbotx channel
.buildConfiguration();
PircBotX bot = new PircBotX(configuration);
//Connect to server
try {
//bot.connect();
bot.startBot();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
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.
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());
}
}
}
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.