0

我正在开发一个使用地图的应用程序。我使用我的 Galaxy nexus 来测试应用程序,但在我包含与地图相关的代码后,它在我的手机上停止工作,但它仍然在模拟器上工作。问题是模拟器没有显示地图,因为它没有 Google Play 服务。

当我尝试启动应用程序时,我没有收到任何错误,但我的手机什么也没做,如果我尝试从应用程序抽屉手动运行它,应用程序就在那里,但它显示“未安装”。

这是Java代码MainActivity.java

package myPackage.android;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import com.actionbarsherlock.view.*;

public class MainActivity extends SherlockFragmentActivity {

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

    //private GoogleMap map;

}

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

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;

    case R.id.action_search:
        final int RESULT=1;
        startActivityForResult(new Intent(MainActivity.this, SearchForm.class), RESULT);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

这是xml布局activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
  <fragment xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/map"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   class="com.google.android.gms.maps.SupportMapFragment" />

和清单:

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

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

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

<uses-permission android:name="android.permission.INTERNET"/>
<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"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<permission
    android:name="myPackage.android.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="myPackage.android.permission.MAPS_RECEIVE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock.Light.DarkActionBar" >

    <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my ap map key"/>


    <activity
        android:name="myPackage.android.SplashScreen"
        android:label="@string/app_name"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar"
        android:permission="android.permission.INTERNET" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="myPackage.android.MainActivity"
        android:label=""
        android:logo="@drawable/logo"
        android:screenOrientation="portrait" 
        android:permission="android.permission.INTERNET" >
    </activity>

    <activity
        android:name="myPackage.android.SearchForm"
        android:label="@string/title_activity_search_form"
        android:parentActivityName="ar.com.package.android.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="myPackage.android.MainActivity" />
    </activity>

</application>

</manifest>

日志猫

05-09 21:17:04.744: D/AndroidRuntime(15507): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-09 21:17:04.744: D/AndroidRuntime(15507): CheckJNI is OFF
05-09 21:17:04.752: D/dalvikvm(15507): Trying to load lib libjavacore.so 0x0
05-09 21:17:04.760: D/dalvikvm(15507): Added shared lib libjavacore.so 0x0
05-09 21:17:04.768: D/dalvikvm(15507): Trying to load lib libnativehelper.so 0x0
05-09 21:17:04.768: D/dalvikvm(15507): Added shared lib libnativehelper.so 0x0
05-09 21:17:04.908: D/AndroidRuntime(15507): Calling main entry com.android.commands.pm.Pm
05-09 21:17:04.916: D/AndroidRuntime(15507): Shutting down VM
05-09 21:17:04.916: D/dalvikvm(15507): GC_CONCURRENT freed 97K, 18% free 482K/584K, paused 1ms+0ms, total 4ms
05-09 21:17:04.924: D/jdwp(15507): Got wake-up signal, bailing out of select
05-09 21:17:04.924: D/dalvikvm(15507): Debugger has detached; object registry had 1 entries
05-09 21:17:05.314: D/AndroidRuntime(15519): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-09 21:17:05.314: D/AndroidRuntime(15519): CheckJNI is OFF
05-09 21:17:05.330: D/dalvikvm(15519): Trying to load lib libjavacore.so 0x0
05-09 21:17:05.330: D/dalvikvm(15519): Added shared lib libjavacore.so 0x0
05-09 21:17:05.338: D/dalvikvm(15519): Trying to load lib libnativehelper.so 0x0
05-09 21:17:05.338: D/dalvikvm(15519): Added shared lib libnativehelper.so 0x0
05-09 21:17:05.486: D/AndroidRuntime(15519): Calling main entry com.android.commands.am.Am
05-09 21:17:05.494: D/dalvikvm(15519): Note: class Landroid/app/ActivityManagerNative; has 157 unimplemented (abstract) methods
05-09 21:17:05.502: I/ActivityManager(407): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=myPackage.android/.SplashScreen} from pid 15519
05-09 21:17:05.502: I/AndroidRuntime(15519): VM exiting with result code 1.
05-09 21:17:05.502: W/ActivityManager(407): Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=myPackage.android/.SplashScreen } from null (pid=15519, uid=2000) requires android.permission.INTERNET
4

2 回答 2

1

好吧,我想通了;我不必在清单中的活动下使用android:permission属性。删除后,该应用程序工作正常。

于 2013-05-11T23:25:07.773 回答
0

你可以试试这段代码。

public class MainActivity extends FragmentActivity {
// for google map
    private GoogleMap mMap;
    SupportMapFragment mapFragment;

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

    mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mMap = mapFragment.getMap();
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);

}

如果您遇到任何问题,请告诉我。

于 2013-05-09T04:26:35.120 回答