Flex ベースの AIR アプリケーションからネイティブ Google マップを表示するネイティブ拡張を作成しています。lee brimelow のデモを見てアイデアを得ることができます: https://plus.google.com/110495278155587072613/posts/degSYVx8423
いくつかのボタンでアクティビティを表示するためだけに、ネイティブ拡張の動作デモを入手しましたが、マップを表示しようとすると行き詰まりました。setContentView(layoutID) で取得している例外は次のとおりです。
05-08 11:48:40.624: I/System.out(27917): WebViewActivity.onCreate がエラーで失敗しました: 05-08 11:48:40.634: I/System.out(27917): "android.view.InflateException: Binary XML file line #9: Error inflating class fragment" 05-08 11:48:40.644: W/dalvikvm(27917): threadid=1: キャッチされない例外で終了するスレッド (グループ = 0x40fd8468) 05-08 11:48:40.654: E/AndroidRuntime(27917): 致命的な例外: メイン 05-08 11:48:40.654: E/AndroidRuntime(27917): java.lang.RuntimeException: アクティビティを開始できません ComponentInfo{air.GoogleMapsApp.debug/com.trasys.googlemaps.WebViewActivity}: java.lang.RuntimeException: 試行中複数の DataRequestDispatcher を作成する 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2351) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2387) で 05-08 11:48:40.654: E/AndroidRuntime(27917): android.app.ActivityThread.access$600(ActivityThread.java:151) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.ActivityThread$H.handleMessage (ActivityThread.java:1331) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.os.Handler.dispatchMessage (Handler.java:99) で 05-08 11:48:40.654: E/AndroidRuntime(27917): android.os.Looper.loop(Looper.java:155) 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.ActivityThread.main (ActivityThread.java:5454) で 05-08 11:48:40.654: E/AndroidRuntime(27917): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) で 05-08 11:48:40.654: E/AndroidRuntime(27917): java.lang.reflect.Method.invoke(Method.java:511) で 05-08 11:48:40.654: E/AndroidRuntime (27917): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1029) で 05-08 11:48:40.654: E/AndroidRuntime (27917): com.android.internal.os.ZygoteInit.main (ZygoteInit.java:796) で 05-08 11:48:40.654: E/AndroidRuntime(27917): dalvik.system.NativeStart.main(ネイティブ メソッド) で 05-08 11:48:40.654: E/AndroidRuntime(27917): 原因: java.lang.RuntimeException: 複数の DataRequestDispatchers を作成しようとしています 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.ak.nb (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.ak.na (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.ak.ha (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.af.wa (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.z.ab.a (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.z.ab.a (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.z.ag.a (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.z.ag.a (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.z.bw.a (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): maps.zronCreateView で (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime (27917): com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact (IMapFragmentDelegate.java:107) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.os.Binder.transact (Binder.java:326) で 05-08 11:48:40.654: E/AndroidRuntime(27917): com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView で (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): com.google.android.gms.maps.MapFragment$b.onCreateView で (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): com.google.android.gms.internal.e$4.a (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): com.google.android.gms.internal.ea で (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): com.google.android.gms.internal.e.onCreateView で (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime(27917): com.google.android.gms.maps.MapFragment.onCreateView で (不明なソース) 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.FragmentManagerImpl.moveToState (FragmentManager.java:809) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1037) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1019) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManager.java:1804) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.Activity.performCreate (Activity.java:5069) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1101) で 05-08 11:48:40.654: E/AndroidRuntime (27917): android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2307) で 05-08 11:48:40.654: E/AndroidRuntime(27917): ... 11 詳細
AIR と Android 間の通信は問題ないと確信しているので、ネイティブ コードのみを投稿します。(マップを削除すると、ネイティブ拡張機能は問題なく動作します)
これがレイアウトxmlファイルです
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<fragment android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="300dp" />
</LinearLayout>
これが私のFREFunctionです
public class GoogleMapsFunction implements FREFunction {
@Override
public FREObject call(FREContext ctx, FREObject[] passedArgs) {
int layoutID, googleMapID;
Intent i = new Intent(ctx.getActivity(), WebViewActivity.class);
layoutID = ctx.getResourceId("layout.activity_google_maps");
googleMapID = ctx.getResourceId("id.map");
i.putExtra("layoutID", layoutID);
i.putExtra("googleMapID", googleMapID);
ctx.getActivity().startActivity(i);
return null;
}
}
ここに私の活動があります
public class WebViewActivity extends Activity {
private GoogleMap map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
int layoutID = getIntent().getIntExtra("layoutID", -1);
setContentView(layoutID);
int googleMapID = getIntent().getIntExtra("googleMapID", -1);
map = ((MapFragment) getFragmentManager().findFragmentById(googleMapID))
.getMap();
} catch(Exception e){
System.out.printf("WebViewActivity.onCreate failed with error:\n\"%s\"\n",
e.toString());
Toast.makeText(this, "WebViewActivity.onCreate failed: " +
e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
ここに私のAndroidManifestがあります
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trasys.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<permission android:name="com.example.helloworld.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.helloworld.permission.C2D_MESSAGE" />
<permission android:name="com.example.helloworld.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.helloworld.permission.MAPS_RECEIVE"/>
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MyApiKey"/>
</application>
</manifest>
com.google.android.gms が表示されます。スタックトレースのエントリなので、すべての Google ライブラリが正しく読み込まれていると思います。
テスト目的で、別の純粋なネイティブ Android アプリケーションを作成しました。このアプリでは、マップを表示するアクティビティを作成できました。このアクティビティは、同じレイアウト XML、同じ Google ライブラリ、および同じ API キーを使用します。
何か案は?