5

私の Android ゲームでは、OpenGL と Android NDK を使用しています。現在、Activity/GLSurfaceView から JNI ネイティブ呼び出しを行うことにより、必要な dpi 値をパラメーターとして渡しています。

現在私は使用しています:

    // request an instance of DisplayMetrics, say 'dm' from android.
    float densityFactor = dm.density;

    // pass this as a parameter using JNI call
    myCustomNativeMethod(densityFactor); # implementation in a 'game.c' file

JNIを使​​用せずにAndroid環境パラメータにアクセスできるかどうか疑問に思っていました(パラメータ)。UIシステムなどと直接通信するのに役立ついくつかの低レベルのNDKヘッダーファイル(.h)をインポートするようなものでしょうか?

私は次のように意味します:

    #import <android_displayparams.h>
    ...        
    float densityfactor = getDisplayParamDensity(); // <- Is this possible?

注: これは好奇心からの質問であり、そのようなメカニズムが適切でない可能性があることは承知しています。

4

1 に答える 1

4

パラメータとしてDPIを渡すJavaアクティビティ/ GLSurfaceViewを使用したセットアップでは、最良のソリューションのように見えます。

NativeActivity を使用する場合は、次を使用してDisplayMetrics.densityDpiを取得できます。

#include <android/configuration.h>
#include <android_native_app_glue.h>
#include <android/native_activity.h>

int32_t getDensityDpi(android_app* app) {
    AConfiguration* config = AConfiguration_new();
    AConfiguration_fromAssetManager(config, app->activity->assetManager);
    int32_t density = AConfiguration_getDensity(config);
    AConfiguration_delete(config);
    return density;
}

残念ながら、DisplayMetrics.xdpi と DisplayMetrics.ydpi を取得する API はありません。

于 2015-01-10T21:33:12.837 に答える