mirror of https://github.com/axmolengine/axmol.git
openUrl function for all platform but on windows RT empty function
This commit is contained in:
parent
ebfdd956c3
commit
2255cf91ba
|
@ -133,6 +133,15 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual Platform getTargetPlatform() = 0;
|
||||
|
||||
/**
|
||||
@brief Open url in default browser
|
||||
@param String with url to open.
|
||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual bool openURL(const std::string &url) = 0;
|
||||
};
|
||||
|
||||
// end of platform group
|
||||
|
|
|
@ -176,6 +176,11 @@ Application::Platform Application::getTargetPlatform()
|
|||
return Platform::OS_ANDROID;
|
||||
}
|
||||
|
||||
bool Application::openURL(const std::string &url)
|
||||
{
|
||||
return openURLJNI(url.c_str());
|
||||
}
|
||||
|
||||
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {
|
||||
|
||||
}
|
||||
|
|
|
@ -84,6 +84,13 @@ public:
|
|||
*/
|
||||
virtual Platform getTargetPlatform();
|
||||
|
||||
/**
|
||||
@brief Open url in default browser
|
||||
@param String with url to open.
|
||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const std::string &url);
|
||||
|
||||
/**
|
||||
@brief This function will be called when the application screen size is changed.
|
||||
@param new width
|
||||
|
|
|
@ -32,9 +32,11 @@ import java.lang.Runnable;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.res.AssetManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager.OnActivityResultListener;
|
||||
import android.util.DisplayMetrics;
|
||||
|
@ -171,6 +173,18 @@ public class Cocos2dxHelper {
|
|||
((Cocos2dxActivity)sActivity).setKeepScreenOn(value);
|
||||
}
|
||||
|
||||
public static boolean openURL(String url) {
|
||||
boolean ret = false;
|
||||
try {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse(url));
|
||||
sActivity.startActivity(i);
|
||||
ret = true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void preloadBackgroundMusic(final String pPath) {
|
||||
Cocos2dxHelper.sCocos2dMusic.preloadBackgroundMusic(pPath);
|
||||
}
|
||||
|
|
|
@ -219,6 +219,20 @@ void setKeepScreenOnJni(bool value) {
|
|||
}
|
||||
}
|
||||
|
||||
extern bool openURLJNI(const char* url) {
|
||||
JniMethodInfo t;
|
||||
|
||||
bool ret = false;
|
||||
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "openURL", "(Ljava/lang/String;)Z")) {
|
||||
jstring stringArg = t.env->NewStringUTF(url);
|
||||
ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg);
|
||||
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
t.env->DeleteLocalRef(stringArg);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// functions for UserDefault
|
||||
bool getBoolForKeyJNI(const char* key, bool defaultValue)
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ extern void enableAccelerometerJni();
|
|||
extern void disableAccelerometerJni();
|
||||
extern void setAccelerometerIntervalJni(float interval);
|
||||
extern void setKeepScreenOnJni(bool value);
|
||||
extern bool openURLJNI(const char* url);
|
||||
// functions for UserDefault
|
||||
extern bool getBoolForKeyJNI(const char* key, bool defaultValue);
|
||||
extern int getIntegerForKeyJNI(const char* key, int defaultValue);
|
||||
|
|
|
@ -86,6 +86,13 @@ public:
|
|||
*/
|
||||
virtual Platform getTargetPlatform();
|
||||
|
||||
/**
|
||||
@brief Open url in default browser
|
||||
@param String with url to open.
|
||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const std::string &url);
|
||||
|
||||
/**
|
||||
@brief This function will be called when the application screen size is changed.
|
||||
@param new width
|
||||
|
|
|
@ -167,6 +167,13 @@ Application::Platform Application::getTargetPlatform()
|
|||
}
|
||||
}
|
||||
|
||||
bool Application::openURL(const std::string &url)
|
||||
{
|
||||
NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSURL* nsUrl = [NSURL URLWithString:msg];
|
||||
return [[UIApplication sharedApplication] openURL:nsUrl];
|
||||
}
|
||||
|
||||
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {
|
||||
|
||||
}
|
||||
|
|
|
@ -136,6 +136,12 @@ Application::Platform Application::getTargetPlatform()
|
|||
return Platform::OS_LINUX;
|
||||
}
|
||||
|
||||
bool Application::openURL(const std::string &url)
|
||||
{
|
||||
std::string op = std::string("open ").append(url);
|
||||
return system(op.c_str())!=-1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// static member function
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -78,6 +78,13 @@ public:
|
|||
*/
|
||||
virtual const char * getCurrentLanguageCode();
|
||||
|
||||
/**
|
||||
@brief Open url in default browser
|
||||
@param String with url to open.
|
||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const std::string &url);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the Resource root path.
|
||||
|
|
|
@ -91,6 +91,13 @@ public:
|
|||
*/
|
||||
virtual Platform getTargetPlatform();
|
||||
|
||||
/**
|
||||
@brief Open url in default browser
|
||||
@param String with url to open.
|
||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const std::string &url);
|
||||
|
||||
/**
|
||||
* Sets the Resource root path.
|
||||
* @deprecated Please use FileUtils::getInstance()->setSearchPaths() instead.
|
||||
|
|
|
@ -213,6 +213,13 @@ LanguageType Application::getCurrentLanguage()
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Application::openURL(const std::string &url)
|
||||
{
|
||||
NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSURL* nsUrl = [NSURL URLWithString:msg];
|
||||
return [[NSWorkspace sharedWorkspace] openURL:nsUrl];
|
||||
}
|
||||
|
||||
void Application::setResourceRootPath(const std::string& rootResDir)
|
||||
{
|
||||
_resourceRootPath = rootResDir;
|
||||
|
|
|
@ -30,6 +30,7 @@ THE SOFTWARE.
|
|||
#include "base/CCDirector.h"
|
||||
#include <algorithm>
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include <shellapi.h>
|
||||
/**
|
||||
@brief This function change the PVRFrame show/hide setting in register.
|
||||
@param bEnable If true show the PVRFrame window, otherwise hide.
|
||||
|
@ -206,6 +207,15 @@ Application::Platform Application::getTargetPlatform()
|
|||
return Platform::OS_WINDOWS;
|
||||
}
|
||||
|
||||
bool Application::openURL(const std::string &url)
|
||||
{
|
||||
WCHAR *temp = new WCHAR[url.size() + 1];
|
||||
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), url.size() + 1, temp, url.size() + 1);
|
||||
HINSTANCE r = ShellExecuteW(NULL, L"open", temp, NULL, NULL, SW_SHOWNORMAL);
|
||||
delete[] temp;
|
||||
return (int)r>32;
|
||||
}
|
||||
|
||||
void Application::setResourceRootPath(const std::string& rootResDir)
|
||||
{
|
||||
_resourceRootPath = rootResDir;
|
||||
|
|
|
@ -75,6 +75,13 @@ public:
|
|||
*/
|
||||
virtual Platform getTargetPlatform();
|
||||
|
||||
/**
|
||||
@brief Open url in default browser
|
||||
@param String with url to open.
|
||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const std::string &url);
|
||||
|
||||
/**
|
||||
* Sets the Resource root path.
|
||||
* @deprecated Please use FileUtils::getInstance()->setSearchPaths() instead.
|
||||
|
|
|
@ -177,6 +177,12 @@ Application::Platform Application::getTargetPlatform()
|
|||
return Platform::OS_WP8;
|
||||
}
|
||||
|
||||
bool Application::openURL(const std::string &url)
|
||||
{
|
||||
//TODO release this method
|
||||
return false;
|
||||
}
|
||||
|
||||
void Application::setResourceRootPath(const std::string& rootResDir)
|
||||
{
|
||||
m_resourceRootPath = rootResDir;
|
||||
|
|
|
@ -63,6 +63,13 @@ public:
|
|||
*/
|
||||
virtual Platform getTargetPlatform() override;
|
||||
|
||||
/**
|
||||
@brief Open url in default browser
|
||||
@param String with url to open.
|
||||
@return true if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const std::string &url);
|
||||
|
||||
/**
|
||||
* Sets the Resource root path.
|
||||
* @deprecated Please use CCFileUtils::sharedFileUtils()->setSearchPaths() instead.
|
||||
|
|
Loading…
Reference in New Issue