Android应用程序无法正常工作 [英] Android application doesn't work

查看:134
本文介绍了Android应用程序无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP复制的机器人code

//umut.tekguc.info/en/content/google-android-map-v2-step-step 这是使用谷歌地图V2应用。我生成我的API密钥,并运行应用程序。当我在实际设备上运行应用程序的应用程序有一些问题,我可以看到消息:您的应用程序已意外采空。
我附上了code和logcat的。

Mainactivity.java

 包info.tekguc.umut.googlemapsmapsandroidv2;进口info.tekguc.umut.googlemapsmapsandroidv2.R;
进口android.os.Bundle;
进口android.app.Activity;
进口android.view.Menu;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.MapFragment;
进口com.google.android.gms.maps.model.LatLng;
进口com.google.android.gms.maps.model.Marker;
进口com.google.android.gms.maps.model.MarkerOptions;公共类MainActivity延伸活动{    私人GoogleMap的MMAP;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        MMAP =((MapFragment)getFragmentManager()findFragmentById(R.id.map)。)的GetMap();
        mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        最后的经纬度CIU =新的经纬度(35.21843892856462,33.41662287712097);
        标记CIU = mMap.addMarker(新的MarkerOptions()
                                  .POSITION(CIU).title伪(我的办公室));
    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }}


activity_main.xml中

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
                    机器人:layout_width =match_parent
                    机器人:layout_height =match_parent
                    机器人:paddingBottom会=@扪/ activity_vertical_margin
                    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
                    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
                    机器人:paddingTop =@扪/ activity_vertical_margin
                    工具:上下文=MainActivity。>                    <的TextView
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:文字=@字符串/参考hello world/>
                    <片段
                        机器人:ID =@ + ID /图
                        机器人:layout_width =match_parent
                        机器人:layout_height =match_parent
                        类=com.google.android.gms.maps.MapFragment/>
                < / RelativeLayout的>

AndroidManifest.xml中

 <?XML版本=1.0编码=UTF-8&GT?;
            <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                包=info.tekguc.umut.googlemapsmapsandroidv2
                安卓版code =1
                机器人:=的versionName1.0>                <用途-SDK
                    安卓的minSdkVersion =14
                    机器人:targetSdkVersion =17/>                    <许可
                    机器人:名字=com.example.androidmapsv2.permission.MAPS_RECEIVE
                    安卓的ProtectionLevel =签名>< /许可>
                <使用许可权
                    机器人:名字=com.example.androidmapsv2.permission.MAPS_RECEIVE/>
                <使用许可权
                    机器人:名字=com.google.android.providers.gsf.permission.READ_GSERVICES/>
                <使用许可权
                    机器人:名字=android.permission.INTERNET对/>
                <使用许可权
                    机器人:名字=android.permission.WRITE_EXTERNAL_STORAG​​E/>
                <使用许可权
                    机器人:名字=android.permission.ACCESS_COARSE_LOCATION/>
                <使用许可权
                    机器人:名字=android.permission.ACCESS_FINE_LOCATION/>                <用途特征
                    机器人:glEsVersion =0x00020000
                    机器人:要求=真/>                <应用
                    机器人:allowBackup =真
                    机器人:图标=@绘制/ ic_launcher
                    机器人:标签=@字符串/ APP_NAME
                    机器人:主题=@风格/ AppTheme>
                      &所述;元数据
                        机器人:名字=com.google.android.maps.v2.API_KEY
                        机器人:值=AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI/>
&所述;元数据
    机器人:名字=com.google.android.gms.version
    机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>
                    <活动
                        机器人:名字=info.tekguc.umut.googlemapsmapsandroidv2.MainActivity
                        机器人:标签=@字符串/ APP_NAME>
                        &所述;意图滤光器>
                            <作用机器人:名字=android.intent.action.MAIN/>                            <类机器人:名字=android.intent.category.LAUNCHER/>
                        &所述; /意图滤光器>
                    < /活性GT;
                < /用途>            < /清单>

LogCat中:

  01-18 18:55:11.437:W / dalvikvm(9874):VFY:无法解析虚方法11035:Linfo / tekguc /了Umut / googlemapsmapsandroidv2 / MainActivity; .getFragmentManager( )Landroid /应用/ FragmentManager;
01-18 18:55:11.437:D / dalvikvm(9874):VFY:在更换运code 0x6e×0008
01-18 18:55:11.437:D / dalvikvm(9874):VFY:死code 0x000b-0045在Linfo / tekguc /了Umut / googlemapsmapsandroidv2 / MainActivity; .onCreate(Landroid / OS /束;)V
01-18 18:55:11.445:I / ApplicationPackageManager(9874):cscCountry是不是德国:XEC
01-18 18:55:11.460:W / dalvikvm(9874):主题ID = 1:螺纹未捕获的异常(组= 0x40018578)退出
01-18 18:55:11.476:E / AndroidRuntime(9874):致命异常:主要
01-18 18:55:11.476:E / AndroidRuntime(9874):了java.lang.RuntimeException:无法启动活动ComponentInfo{info.tekguc.umut.googlemapsmapsandroidv2/info.tekguc.umut.googlemapsmapsandroidv2.MainActivity}: android.view.InflateException:二进制XML文件行#15:错误充气类片段
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:935)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.os.Handler.dispatchMessage(Handler.java:99)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.os.Looper.loop(Looper.java:130)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.ActivityThread.main(ActivityThread.java:3687)
01-18 18:55:11.476:E / AndroidRuntime(9874):在java.lang.reflect.Method.invokeNative(本机方法)
01-18 18:55:11.476:E / AndroidRuntime(9874):在java.lang.reflect.Method.invoke(Method.java:507)
01-18 18:55:11.476:E / AndroidRuntime(9874):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)
01-18 18:55:11.476:E / AndroidRuntime(9874):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-18 18:55:11.476:E / AndroidRuntime(9874):在dalvik.system.NativeStart.main(本机方法)
01-18 18:55:11.476:E / AndroidRuntime(9874):android.view.InflateException:二进制XML文件行#15:错误充气类片段产生的原因
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-18 18:55:11.476:E / AndroidRuntime(9874):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.Activity.setContentView(Activity.java:1657)
01-18 18:55:11.476:E / AndroidRuntime(9874):在info.tekguc.umut.googlemapsmapsandroidv2.MainActivity.onCreate(MainActivity.java:21)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-18 18:55:11.476:E / AndroidRuntime(9874):11 ...更多
01-18 18:55:11.476:E / AndroidRuntime(9874):抛出java.lang.ClassNotFoundException:致android.view.fragment装载机dalvik.system.PathClassLoader [/data/app/info.tekguc.umut.googlemapsmapsandroidv2 -1.apk]
01-18 18:55:11.476:E / AndroidRuntime(9874):在dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-18 18:55:11.476:E / AndroidRuntime(9874):在java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-18 18:55:11.476:E / AndroidRuntime(9874):在java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.createView(LayoutInflater.java:471)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
01-18 18:55:11.476:E / AndroidRuntime(9874):在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-18 18:55:11.476:E / AndroidRuntime(9874):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-18 18:55:11.476:E / AndroidRuntime(9874):20 ...更多


解决方案

也许你可以使用简单的JavaScript为这样的选择。

写在记事本该code和另存为HTML。

 <!DOCTYPE HTML>
< HTML和GT;
  < HEAD>
    <间的charset =UTF-8>
    <标题>标记动画< /标题>
    <风格>
      HTML,身体,#地图帆布{
        高度:100%;
        保证金:0像素;
        填充:0像素
      }
    < /风格>
    &所述; SCRIPT SRC =htt​​ps://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false>&下; /脚本>
    <脚本>
//下面的示例创建在LOCATION1一个标记,LOCATION2
使用DROP动画//。点击该标记将切换
//反弹动画和没有动画的动画。
VAR LOCATION1 =新google.maps.LatLng(-7.298716,112.766686);
VAR LOCATION2 =新google.maps.LatLng(-7.298716,112.766868);
VAR标记;
VAR地图;
VAR图像='marks.png';
VAR信息;
VAR数据='< D​​IV ID =内容>'+
'< / DIV>'+
'< H1 ID =第一级=第一>您的标题< / H1>'+
'< D​​IV ID =身体与GT;'+
'< P>此处键入您的身体+
'&所述; / P>'+
'< P>< A HREF =链接>更多...< / A>< / P>'+
'< / DIV>'+
'< / DIV>';函数初始化(){
  VAR的MapOptions = {
    变焦:17,
    中心:LOCATION1
  };  地图=新google.maps.Map(的document.getElementById('地图画布'),
          的MapOptions);  标记=新google.maps.Marker({
    地图:地图,
    拖动:真实,
    图标:图像,
    动画:google.maps.Animation.DROP,
    位置:LOCATION2
  });  google.maps.event.addListener(标记,'点击',toggleBounce);
}功能toggleBounce(){  如果(marker.getAnimation()!= NULL){
    marker.setAnimation(NULL);
    info.close();
  }其他{
  marker.setAnimation(google.maps.Animation.BOUNCE);
    信息=新google.maps.InfoWindow({
  内容:数据
  })开(地图,标记);  }
}google.maps.event.addDomListener(窗口'负荷',初始化);    < / SCRIPT>
  < /头>
  <身体GT;
    < D​​IV ID =地图画布>< / DIV>
  < /身体GT;
< / HTML>

html插入资产的文件夹中,然后用的WebView activity_main.xml中

 <的WebView
        机器人:ID =@ + ID /网络
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT/>

MainActivity.java

 进口android.app.Activity;
进口android.os.Bundle;
进口android.view.Menu;
进口android.webkit.WebView;公共类MainActivity延伸活动{
    web视图的WebView;    @燮pressLint(SetJavaScriptEnabled)
    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        web视图=(的WebView)findViewById(R.id.web);
        webView.loadUrl(文件:///android_asset/file.html);
        webView.getSettings()setJavaScriptEnabled(真)。    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }}

希望能有所帮助。对不起,我的英语

Copied the android code from http://umut.tekguc.info/en/content/google-android-map-v2-step-step This is the application that use Google Maps v2. I generated my Api key and run the application. When i run the application on the real device the application has some problems and i can see the message: Your application has stoped unexpectedly. I have attached the code and logCat.

Mainactivity.java

package info.tekguc.umut.googlemapsmapsandroidv2;

import info.tekguc.umut.googlemapsmapsandroidv2.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;


import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 

        mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
        Marker ciu = mMap.addMarker(new MarkerOptions()
                                  .position(CIU).title("My Office"));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}


activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingBottom="@dimen/activity_vertical_margin"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingTop="@dimen/activity_vertical_margin"
                    tools:context=".MainActivity" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/hello_world" />
                    <fragment
                        android:id="@+id/map"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        class="com.google.android.gms.maps.MapFragment"/>
                </RelativeLayout>

AndroidManifest.xml

            <?xml version="1.0" encoding="utf-8"?>
            <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                package="info.tekguc.umut.googlemapsmapsandroidv2"
                android:versionCode="1"
                android:versionName="1.0" >

                <uses-sdk
                    android:minSdkVersion="14"
                    android:targetSdkVersion="17" />

                    <permission 
                    android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" 
                    android:protectionLevel="signature"></permission>
                <uses-permission 
                    android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
                <uses-permission 
                    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
                <uses-permission 
                    android:name="android.permission.INTERNET"/>
                <uses-permission 
                    android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
                <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:allowBackup="true"
                    android:icon="@drawable/ic_launcher"
                    android:label="@string/app_name"
                    android:theme="@style/AppTheme" >
                      <meta-data
                        android:name="com.google.android.maps.v2.API_KEY"
                        android:value="AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI"/>
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
                    <activity
                        android:name="info.tekguc.umut.googlemapsmapsandroidv2.MainActivity"
                        android:label="@string/app_name" >
                        <intent-filter>
                            <action android:name="android.intent.action.MAIN" />

                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                    </activity>
                </application>

            </manifest>

LogCat:

01-18 18:55:11.437: W/dalvikvm(9874): VFY: unable to resolve virtual method 11035: Linfo/tekguc/umut/googlemapsmapsandroidv2/MainActivity;.getFragmentManager ()Landroid/app/FragmentManager;
01-18 18:55:11.437: D/dalvikvm(9874): VFY: replacing opcode 0x6e at 0x0008
01-18 18:55:11.437: D/dalvikvm(9874): VFY: dead code 0x000b-0045 in Linfo/tekguc/umut/googlemapsmapsandroidv2/MainActivity;.onCreate (Landroid/os/Bundle;)V
01-18 18:55:11.445: I/ApplicationPackageManager(9874): cscCountry is not German : XEC
01-18 18:55:11.460: W/dalvikvm(9874): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-18 18:55:11.476: E/AndroidRuntime(9874): FATAL EXCEPTION: main
01-18 18:55:11.476: E/AndroidRuntime(9874): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.tekguc.umut.googlemapsmapsandroidv2/info.tekguc.umut.googlemapsmapsandroidv2.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.os.Looper.loop(Looper.java:130)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.ActivityThread.main(ActivityThread.java:3687)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at java.lang.reflect.Method.invokeNative(Native Method)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at java.lang.reflect.Method.invoke(Method.java:507)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at dalvik.system.NativeStart.main(Native Method)
01-18 18:55:11.476: E/AndroidRuntime(9874): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.Activity.setContentView(Activity.java:1657)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at info.tekguc.umut.googlemapsmapsandroidv2.MainActivity.onCreate(MainActivity.java:21)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-18 18:55:11.476: E/AndroidRuntime(9874):     ... 11 more
01-18 18:55:11.476: E/AndroidRuntime(9874): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/info.tekguc.umut.googlemapsmapsandroidv2-1.apk]
01-18 18:55:11.476: E/AndroidRuntime(9874):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.createView(LayoutInflater.java:471)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-18 18:55:11.476: E/AndroidRuntime(9874):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-18 18:55:11.476: E/AndroidRuntime(9874):     ... 20 more

解决方案

Maybe you can use simple javascript as alternative like this.

write this code on notepad and save as html.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Marker Animations</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
// The following example creates a marker in location1, location2
// using a DROP animation. Clicking on the marker will toggle
// the animation between a BOUNCE animation and no animation.


var location1 = new google.maps.LatLng(-7.298716, 112.766686);
var location2 = new google.maps.LatLng(-7.298716, 112.766868);
var marker;
var map;
var image = 'marks.png';
var info;
var data = '<div id="content">'+
'</div>'+
'<h1 id="first" class="first">Your Title </h1>'+
'<div id="body">'+
'<p>type your body here'+
'</p>'+
'<p><a href="link">Read More...</a></p>'+
'</div>'+
'</div>';

function initialize() {
  var mapOptions = {
    zoom: 17,
    center: location1
  };

  map = new google.maps.Map(document.getElementById('map-canvas'),
          mapOptions);

  marker = new google.maps.Marker({
    map:map,
    draggable:true,
    icon: image,
    animation: google.maps.Animation.DROP,
    position: location2
  });

  google.maps.event.addListener(marker, 'click', toggleBounce);
}

function toggleBounce() {

  if (marker.getAnimation() != null) {
    marker.setAnimation(null);
    info.close();
  } else {
  marker.setAnimation(google.maps.Animation.BOUNCE);
    info = new google.maps.InfoWindow({
  content: data 
  }).open(map, marker);

  }
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

insert html into assets folder, then use webview in activity_main.xml

<WebView
        android:id="@+id/web"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;

public class MainActivity extends Activity {
    WebView webView;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView = (WebView) findViewById(R.id.web);
        webView.loadUrl("file:///android_asset/file.html");
        webView.getSettings().setJavaScriptEnabled(true);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

hopefully can help. Sorry for my english

这篇关于Android应用程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆