Android/App개발2011. 6. 2. 13:40


JNI, jstring type example
Java의 String 을 JNI에서 다루는 예

JNI Functions Reference : http://download.oracle.com/javase/1.4.2/docs/guide/jni/spec/functions.html#wp17314

JNITest.java

public class  JNITest
{
 static{
  System.loadLibrary("my_dll");
 }

 public native String greeting(String name);

 public static void main(String[] args) 
 {
  JNITest test = new JNITest();
  String result = test.greeting("Smith");
  System.out.println("C 함수 리턴값:  "+result);
 }
}



JNITest.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNITest */

#ifndef _Included_JNITest
#define _Included_JNITest
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     JNITest
 * Method:    greeting
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
 */

JNIEXPORT jstring JNICALL Java_JNITest_greeting
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus
}
#endif
#endif





my_dll.c

#include <stdio.h>
#include "JNITest.h"
#include <string.h>

JNIEXPORT jstring JNICALL Java_JNITest_greeting
  (JNIEnv *env, jobject obj, jstring jstr) {

 const char *name = (*env)->GetStringUTFChars(env, jstr, NULL);//Java String to C Style string
 char msg[60] = "Hello ";
 jstring result;

 strcat(msg, name);
 (*env)->ReleaseStringUTFChars(env, jstrname);
 puts(msg);

 result = (*env)->NewStringUTF(env, msg); // C style string to Java String
 return result;

}



Posted by 삼스
Android/Porting2011. 5. 25. 14:28

MP3 encoder가 필요해서 작업중이엇는데 누가 아주 잘 설명을 해두었네요.
필요하신 분들을 step by step으로 따라하심 됩니다.

http://blog.libertadtech.com/2011/02/porting-lame-encoder-to-android-arm.html
 

porting compiling lame encoder to Android ARM arch using Android NDK

I was looking for a mp3 encoding application in Android Market, and found very few, the reason I think Android doesn't support mp3 encoding is because mp3 is patented technology. Another reason is I guess people prefer Java programming and Android SDK rather than Android native development kit.

Nevertheless compiling libmp3lame library for Android using Android NDK is very easy actually.
1. download Android NDK(also you need Android SDK and Eclipse with ADT plugin) and create simple project.
2. create directory called "jni" in your project's directory.
3. download lame sources, extract, copy all sources from directory libmp3lame to jni directory. Also copy lame.h which is located in include directory of lame sources.
4. create jni/Android.mk file. it should look like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := mp3lame
LOCAL_SRC_FILES := bitstream.c fft.c id3tag.c mpglib_interface.c presets.c  quantize.c   reservoir.c tables.c  util.c  VbrTag.c encoder.c  gain_analysis.c lame.c  newmdct.c   psymodel.c quantize_pvt.c set_get.c  takehiro.c vbrquantize.c version.c
include $(BUILD_SHARED_LIBRARY)
5. clean lame sources, remove what's left from GNU autotools, Makefile.am Makefile.in libmp3lame_vc8.vcproj logoe.ico depcomp, folders i386 vector.
6. edit file jni/utils.h, and replace definition extern ieee754_float32_t fast_log2(ieee754_float32_t x);
with this extern float fast_log2(float x);
7. go to the root directory of your Android project and run $pathtoandroidndk/ndk-build and you're done, you'll have limp3lame.so compiled. 
Posted by 삼스
Android/App개발2011. 5. 11. 11:02

Intent.ACTION_SEND를 이용하여 Email, MMS 앱에 파라메터를 번들형태로 넘겨서 해당 액티비티를 호출하는 것이 가능하다.

Email의 경우 아래와 같이 하면 된다.


Intent i=new Intent(Intent.ACTION_SEND); 

i.addCategory(Intent.CATEGORY_DEFAULT); 

    

// for EMail
// mimetype

i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "제목입니다."); 

i.putExtra(Intent.EXTRA_TEXT, "본문이구요 ....");

i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"user1@website.com"}); 

i.putExtra(Intent.EXTRA_CC, new String[]{"user_cc1@website.com"user_cc2@website.com"}); 

i.putExtra(Intent.EXTRA_BCC, new String[]{"user_bcc1@website.com"}); 

// 파일 첨부
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mic_rec3.wav"));

// 앱선택 박스를 띄움.

startActivity(Intent.createChooser(i, "How do you want to send message?"));


MMS의 경우는 아래와 같이 Extra정보를 설정한다.    

// for MMS

i.putExtra("address", "07011111111;01022222222");

i.putExtra("exit_on_sent", true);

i.putExtra("sms_body", "MMS 테스트입니다."); 

startActivity(Intent.createChooser(i, "How do you want to send message?"));


앱선택박스를 띄우지 않고 바로 특정 앱(MMS, GMail)으로 바로 연결되도록 하려면 해당하는 액티비티 Component를 Intent에 등록하면 된다.

// com.google.android.gm 패키지의 ComposeActivityGmail 액티비티를 명시적으로 기입해도 될듯~!

i.setComponent(new ComponentName("com.google.android.gm","com.google.android.gm.ComposeActivity"));


그러나 위와 같이 하면 permission에러가 나면서 해당 액티비티가 호출되지 않는다.
권한문제를 피해가기 위해 Intent.createChooser()를 이용하여 해당 액티비티로 연결하도록 되어 있다.

이를 피하기 위해서는 권한 문제가 없는 자체적인 Mail client나 MMS client를 직접 작성해야 할것으로 보인다.
그러나 이 문제도 권한문제로 인해 구현이 불가할 수 있다.



Posted by 삼스