BbaDdo :: cocos2d-x 안드로이드 웹페이지 호출 cocos2d-x loading a wep page in Android


 

 

cocos2d-x 안드로이드 웹페이지 호출

cocos2d-x  loading a wep page in Android

 

1.   JNI 등록할    UrlJni.h ,   UrlJni.cpp  클래스파일 작성

ð  2개 파일들을

(사용자폴더이름)\cocos2dx\platform\android\jni 폴더에 저장

 

======

UrlJni.h

======

#ifndef __ANDROID_URL_JNI_H__

#define __ANDROID_URL_JNI_H__

 

extern "C"

{

    extern void openURLJNI(const char* url);

}

 

#endif

 

 

========

UrlJni.cpp

========

#include "UrlJni.h"

#include "JniHelper.h"

 

#include <jni.h>

 

using namespace cocos2d;

 

extern "C"

{

    void openURLJNI(const char* url)

    {

        JniMethodInfo t;

        if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxActivity"

                        ,"openURL"

                        ,"(Ljava/lang/String;)V"))

        {

            jstring StringArg1 = t.env->NewStringUTF(url);

            t.env->CallStaticVoidMethod(t.classID,t.methodID, StringArg1);

        }

 

    }

}

 

 

2.    (사용자폴더이름)\cocos2dx\Android.mk  에 등록

è 아래 빨간색 코드 한줄

========

Android.mk

========

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := cocos2dx_static

LOCAL_MODULE_FILENAME := libcocos2d

LOCAL_SRC_FILES := \

CCConfiguration.cpp \

CCDrawingPrimitives.cpp \

CCScheduler.cpp \

CCCamera.cpp \

actions/CCAction.cpp \

. . . . . . . . . . . . .

. . . . . . . . . . . . . 

. . . . . . . . . . . . .

. . . . . . . . . . . . . 

platform/android/jni/JniHelper.cpp \

platform/android/jni/IMEJni.cpp \

platform/android/jni/MessageJni.cpp \

platform/android/jni/SensorJni.cpp \

platform/android/jni/SystemInfoJni.cpp \

platform/android/jni/TouchesJni.cpp \

platform/android/jni/UrlJni.cpp \

script_support/CCScriptSupport.cpp \

sprite_nodes/CCAnimation.cpp \

sprite_nodes/CCAnimationCache.cpp \

sprite_nodes/CCSprite.cpp \

. . . . . . . . . . . . .

. . . . . . . . . . . . . 

 

3.     Cocos2dxActivity.java 에 멤버변수와 메서드를 추가한다.

(사용자프로젝트이름)\ android\src\org\cocos2dx\lib 폴더에 있음

ð  아래 코드 빨간색 코드

 

================

Cocos2dxActivity.java

================

package org.cocos2dx.lib;

import android.app.Activity;

      import android.app.AlertDialog;

      import android.app.Dialog;

      import android.content.DialogInterface;

      import android.content.Intent;

      import android.content.pm.ApplicationInfo;

      import android.content.pm.PackageManager;

      import android.content.pm.PackageManager.NameNotFoundException;

      import android.net.Uri;

      import android.os.Bundle;

      import android.os.Handler;

      import android.os.Message;

      import android.util.DisplayMetrics;

      import android.util.Log;

 

      public class Cocos2dxActivity extends Activity{

             private static Cocos2dxMusic backgroundMusicPlayer;

             private static Cocos2dxSound soundPlayer;

             private static Cocos2dxAccelerometer accelerometer;

             private static boolean accelerometerEnabled = false;

             private static Handler handler;

             private final static int HANDLER_SHOW_DIALOG = 1;

             private static String packageName;

private static native void nativeSetPaths(String apkPath);

 

             //===============

             //add url member

             //===============

             private static Activity meUrl = null;

 

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

       

 

             //===============

             //add url member

             //===============

             meUrl = this;

 

    // get frame size

    DisplayMetrics dm = new DisplayMetrics();

              getWindowManager().getDefaultDisplay().getMetrics(dm);

              accelerometer = new Cocos2dxAccelerometer(this);

 

              // init media player and sound player

        backgroundMusicPlayer = new Cocos2dxMusic(this);

        soundPlayer = new Cocos2dxSound(this);

       

             // init bitmap context

        Cocos2dxBitmap.setContext(this);

       

        handler = new Handler(){

        public void handleMessage(Message msg){

                         switch(msg.what){

                         case HANDLER_SHOW_DIALOG:

                                      showDialog(((DialogMessage)msg.obj).title, ((DialogMessage)msg.obj).message);

                                      break;

                             }

 }

        };

    }

 

//===============

//add url method

//===============

public static void openURL(String url){

             Intent i = new Intent(Intent.ACTION_VIEW); 

             i.setData(Uri.parse(url));

             meUrl.startActivity(i);

   }

//===============

 

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

 

 

 

4.     사용하고자 하는 해당 클래스에서 코딩

 

//헤더파일 인클루드 코드

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)        

#include "platform/android/jni/UrlJni.h"

#endif

 

//호출 코드

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)       

             openURLJNI("http://bbaddoroid.tistory.com");

#endif

 

 

 끝.

 

저작자 표시 비영리 변경 금지
신고
1 2 3 4 5 6 7 8 9 10 ··· 16 

카운터

Total : 14,880 / Today : 0 / Yesterday : 13
get rsstistory!