• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Hi.I have a problem about with jni

scorpi10

Newbie
Jan 11, 2012
11
0
I want to learn call a c code with jni in android.It's compiling.But it doesn't work.
This is my Android.mk file:
Code:
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := WebOynatici
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := WebOynatici.c
LOCAL_LDLIBS    := -llog 

include $(BUILD_SHARED_LIBRARY)
This is my C source code:
Code:
#include "stdio.h"
#include <jni.h>


JNIEXPORT void JNICALL Java_com_WebOynatici_WebOynaticiActivity_DosyayaYaz(JNIEnv * env,jobject obj){
char * html2;
html2="<!DOCTYPE html>\
            <html>\
            <head>\
            <body>\
            <object\
                data=\
            http://www.youtube.com/embed/6nFKPVfDrgU?feature=player_detailpage\
                width=\
            400 height=\
                300\
            >\
                <param value=\
            http://www.youtube.com/embed/6nFKPVfDrgU?feature=player_detailpage\
                >\
                <embed\
                src=\
                http://www.youtube.com/embed/6nFKPVfDrgU?feature=player_detailpage\
                type=\
                application/x-shockwaqvw-flash\
                width=\
                200\ height=\
                200\
            >\


            </object>\
            </body>\
            </head>\
            </html>"; 
FILE * dosya;
dosya=fopen("mnt/sdcard/Res/object.html","wb");
fwrite(html2,1,strlen(html2),dosya);
}
And tihs is my java code:
Code:
package com.WebOynatici;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;

    
    
    

public class WebOynaticiActivity extends Activity {
    WebView WEB;
    String klasor="mnt/sdcard/Res";
    String adres="mnt/sdcard/Res/object.html";
    public native void DosyayaYaz();
    static{
        
        System.loadLibrary("WebOynatici");
        
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        

    
        super.onCreate(savedInstanceState);
        WebOynaticiActivity Yen=new WebOynaticiActivity();
        Yen.DosyayaYaz();
        setContentView(R.layout.main);
        WEB=(WebView)findViewById(R.id.Web);
        WEB.getSettings().setJavaScriptEnabled(true);;
        WebSettings webSettings = WEB.getSettings();
        webSettings.setJavaScriptEnabled(true);
        WEB.addJavascriptInterface(new JavaScriptInterface(this), "MyAndroid");
        WEB.setWebChromeClient(new WebChromeClient());
        WEB.loadUrl(adres);
    }
    public class JavaScriptInterface {
        Context mContext;
        JavaScriptInterface(Context c) {
            mContext = c;
        }
        public void receiveValueFromJs(String str) {
            Toast.makeText(mContext, "Received Value from JS: " + str,Toast.LENGTH_SHORT).show();
          }
   }
  
}

And i am working with Eclipse on Windows platform.
Where is my error?Thank u for ur helps :)
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones