'Android/App개발'에 해당되는 글 86건
- 2009.10.14 <Android market관련 테스트할 때 쉬운 방법 > 2
- 2009.09.07 C에 맞게 자동으로 JNI를 만들어 줌. 1
- 2009.08.28 softKeyboard 띄위기 2
- 2009.08.28 도넛부터 탑재되는 통합검색솔루션 Android Search
- 2009.08.15 framework 디버그 하기.. 4
- 2009.08.14 Emulator의 system 폴더 속성 바꾸기.. 1
- 2009.08.04 AlarmManager & PowerManager 1
- 2009.07.26 PAAD 의 Intent 설명부분.. 3
- 2009.07.24 Service를 확장한 class들... 1
- 2009.07.24 android: App to lib call structure 1
메시지 5개 - 모두 접기 |
Hi all,
I have been experimenting with using native code on the Android Let's start with my successes so far. I have tested the sample My goal however is to access the functionality of an (existing) C++ To the best of my knowledge, the most straightforward way to do so On Android however, I have up till now not been able to achieve the Here is my source code. First there is the "native" C++ class, which newtestclass.h #ifndef NEWTESTCLASS_H class NewTestClass void setX(const int x); };
#endif // NEWTESTCLASS_H newtestclass.cpp #include "newtestclass.h" NewTestClass::NewTestClass() : m_x(0) }
NewTestClass::~NewTestClass() { }
void NewTestClass::setX(const int x) { m_x = x; }
int NewTestClass::getX() const { return m_x; }
As you can see this is pretty straightforward C++ code, to make sure the problems are not being caused by advanced C++ constructs. As instructed in the SWIG tutorial, I have written a SWIG interface newtestclass.i %module newtestclassmodule %include "newtestclass.h" Again very simple. On this interface class, I invoke the swig tool as swig -c++ -o newtestclass_wrap.cpp -package com.example.newtest -java which generates the file newtestclass_wrap.cpp. If desired/needed, I Besides the newtestclass_wrap.cpp file, the swig tool also generates a Finally, I attempt to use the Java NewTestClass inside the onCreate public class RunMe extends Activity { System.loadLibrary("newtest"); NewTestClass ntc = new NewTestClass(); TextView tv = new TextView(this); }
I compile and run the Android activity class using the Eclipse ADT plug-in. When executing the Android application, LogCat output suggests the libnewtest.so library is loaded successfully. However I do get some warnings: D/dalvikvm( 2027): Trying to load lib /data/data/com.example.newtest/ As soon as the application tries to instantiate a NewTestClass object I/DEBUG ( 539): *** *** *** *** *** *** *** *** *** *** *** *** *** I hope my explanation has been sufficiently elaborate. Has anyone any Many thanks in advance, |
As I did not find any solution to this strange problem, I tried compiling the native library using the agcc build script (http:// plausible.org/andy/agcc). Surprisingly, now everything works as expected! In other words, I am able to use my native code in Java as I would in a C++ environment. Unfortunately however, I still have no clue as to why compilation |
I have used the SWIG framework on Android and it works. Regards, On Mon, Jul 6, 2009 at 8:10 PM, Maarten Wijnants <maarten.wijna...@gmail.com |
Hello Sridhar, Many thanks for your reply! I am sorry I did not respond sooner, I On 31 jul, 16:32, Sridhar M <sridhar....@gmail.com> wrote: > Maarten, Indeed I did not implement the JNI_OnLoad method. I saw LogCat > I have used the SWIG framework on Android and it works. printing a warning about this, but adding the method did not help me. Maybe I did something wrong in the JNI_OnLoad implementation, I'm not sure. Anyway, using the agcc build script, I was able to successfully get SWIG to work, WITHOUT the JNI_OnLoad method. So I am still not really sure whether native JNI method registering is absolutely necessary. > > Regards,
Once more my gratitude for your reply! Maybe in the future I will > Sridhar again look into NDK native library building (instead of using the agcc build script). When so, I will definitely look into your suggestion of registering native methods in the JNI_OnLoad method. Greetz, |
You are welcome! Hope it helps. Regards, On Wed, Aug 26, 2009 at 5:31 PM, Maarten Wijnants < |
http://www.engadget.com/2009/05/27/
android-2-0-donut-features-demoed-at-google-i-o/
도넛부터 탑재되는 통합검색솔루션
- Web은 물론이고 local의 contacts, mail, application content등을 하나로 검색 관리 가능
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); ..screen will stay on during this section.. wl.release();
Flag Value | CPU | Screen | Keyboard |
---|---|---|---|
PARTIAL_WAKE_LOCK | On* | Off | Off |
SCREEN_DIM_WAKE_LOCK | On | Dim | Off |
SCREEN_BRIGHT_WAKE_LOCK | On | Bright | Off |
FULL_WAKE_LOCK | On | Bright | Bright |
Flag Value | Description |
---|---|
ACQUIRE_CAUSES_WAKEUP | Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately. |
ON_AFTER_RELEASE | If this flag is set, the user activity timer will be reset when the WakeLock is released, causing the illumination to remain on a bit longer. This can be used to reduce flicker if you are cycling between wake lock conditions. |
이 방법은 "런타임 메뉴 추가"기능을 의미한다.
<activity android:name=".NostromoController">
<intent-filter android:label="궤도로부터의 핵 공격">
<action android:name="com.pad.nostromo.NUKE_FROM_ORBIT"/>
<data android:mimeType="vnd.moonbase.cursor.item/*/>
<category android:name="android.intent.category.ALTERNATIVE"/>
<category android:name="android.intent.category.SELECTED_ALTERNATIVE"/>
</activity>
위 action을 또 다른 액티비티의 메뉴에서 동적으로 사용할 수 있도록 만들 수 있다.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
Intent intent = new Intent();
intent.setData(MoonBaseProvider.CONTENT_URI);
intent.addCategory(Intent.CATEGORY_SELECTED_ALTERNATIVE);
int menuGroup = 0;
int menuItemId = 0;
int menuItemOrder = Menu.NONE;
ComponentName caller = getComponentName();
Intent[] specificIntents = null;
MenuItem[] outSpecificItems = null;
menu.addIntentOptions(menuGroup,
menuItemId,
menuItemOrder,
caller,
specificIntents,
intent,
Menu.FLAG_APPEND_TO_GROUP,
outSpecificItems);
return true;
}
** Broadcast Intent **
인텐트는 액티비티를 호출하는데에만 사용하는 것이 아니라 콤포넌트들간에 메시지를 전달하는데 사용될 수 있다. 어플리케이션내에 브로드캐스트수신자를 장착하여 특정 방송메세지에 귀기울이도록 할 수 있다.
// 방송하기
1. Intent 생성
Intent intent = new Intent(NEW_LIFEFORM_DELETED);
intent.putExtra("lifeformName", lifeformType);
intent.putExtra("longitude", currentLongitude);
intent.putExtra("latitude", currentLatitude);
2. send
sendBroadcast(intent);
// 방송듣기
1. BroadcastReceiver 생성
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Content context, Intent intent) {
// TODO :수신한 방송에 대해 처리를 한다.
}
}
2. AndroidManifest.xml에 수신자를 등록한다.
<receiver android:name=".LifeformDeletedBroadcastReceiver">
<intent-filter>
<action android:name="com.paad.action.NEW_LIFEFORM"/>
</intent-filter>
</receiver>
3. 또는 code상에서 수신자를 등록하거나 해재할 수 있다. 이 처럼 동적으로 액티비티가 활성화되어 있을경우에만 수신할 수 있도록 하는 제어가 가능하다.
//등록하기
IntentFilter filter = new IntentFilter(NEW_LIFEFORM_DETECTED);
LifeformDetectedBroadcastReceiver r = new LifeformDetectedBroadcastReceiver();
registerReceiver(r, filter);
// 해재하기
unregisterReceiver( r );
안드로이드 시스템에서 정의되어 있는 방송의 종류는 아래와 같다.
ACTION_BOOT_COMPLETED
ACTION_CAMERA_BUTTON
ACTION_DATE_CHANGED, ACTION_TIME_CHANGED
ACTION_GTALK_SERVICE_CONNECTED, ACTION_GTALK_SERVICE_DISCONNECTED
ACTION_MEDIA_BUTTON
ACTION_MEDIA_EJECT
ACTION_MEDIA_MOUNTED, ACTION_MEDIA_UNMOUNTED
ACTION_SCREEN_OFF, ACTION_SCREEN_ON
ACTION_TIMZONE_CHANGED
// ... http://developer.android.com/reference/android/content/Intent.html