我正在使用Android Studio制作具有一些按钮的应用。当我点击按钮电话"找到"时,它会打开谷歌地图,但不会显示地图,而是一张空白地图。
这里是我的代码
android manifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
android:versionCode="1"
android:versionName="1.0" >
<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.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ssss"
android:label="Active ATM"
android:theme="@style/AppTheme" >
<activity
android:name="AcctiveATM"
android:label="Active ATM" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".help"
android:label="@string/title_activity_help" >
<intent-filter>
<action android:name="com.example.ahmed.activeatm.help" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".map1"
android:label="@string/title_activity_map1" >
<intent-filter>
<action android:name="com.google.android.gms.maps.SupportMapFragment" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
主页面.java
package com.example.ahmed.activeatm;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DigitalClock;
import android.widget.Toast;
public class AcctiveATM extends AppCompatActivity {
private static Button button_sbm;
private static Button button_sbm1;
private static Button button_sbm2;
private static DigitalClock digital;
private static Button button_sbm3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_acctive_atm);
onButtonClickListener();
onButtonClickListenerr();
onClickButtonListener();
setButton_sbm3ClickButtonListener();
}
public void onButtonClickListener(){
button_sbm = (Button)findViewById(R.id.button);
button_sbm.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder a_builder = new AlertDialog.Builder(AcctiveATM.this);
a_builder.setMessage("DO you want to close this app:")
.setCancelable(false)
.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = a_builder.create();
alert.setTitle("Alert!!");
alert.show();
}
}
);
}
public void onButtonClickListenerr(){
button_sbm1 = (Button)findViewById(R.id.button2);
button_sbm1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder a_builder = new AlertDialog.Builder(AcctiveATM.this);
a_builder.setMessage("this application enabels customers to find " +
"ATM machines near them using google maps and mobile GPS" +
"\n\n" +
"Devolop by ^_^:\n\n -alzergine\n-wd malik\n-alaa mohamed")
.setCancelable(false)
.setNegativeButton("Dissmise", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = a_builder.create();
alert.setTitle("About...");
alert.show();
}
}
);
}
public void onClickButtonListener() {
button_sbm2 = (Button)findViewById(R.id.button3);
button_sbm2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.example.ahmed.activeatm.help");
startActivity(intent);
}
}
);
}
public void setButton_sbm3ClickButtonListener() {
button_sbm3 = (Button)findViewById(R.id.button4);
button_sbm3.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
//Intent intent = new Intent("com.google.android.gms.maps.SupportMapFragment");
Intent i = new Intent(getApplicationContext(),map1.class);
startActivity(i);
// setContentView(R.layout.activity_map1);
// map1 a = new map1();
//a.setUpMapIfNeeded();
}
}
);
}}
map.xml
<fragment 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:id="@+id/map"
tools:context="com.example.ahmed.activeatm.map1"
android:name="com.google.android.gms.maps.SupportMapFragment" />
主页布局
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".AcctiveATM"
android:background="#b8fff5">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@color/abc_search_url_text_normal"
android:textSize="@dimen/abc_text_size_title_material"
android:textStyle="bold"
android:theme="@android:style/Animation.Dialog" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About"
android:id="@+id/button2"
android:textSize="@dimen/abc_text_size_title_material"
android:textStyle="bold"
android:theme="@android:style/Animation.Dialog"
android:background="@color/abc_search_url_text_normal"
android:layout_alignTop="@+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Help"
android:id="@+id/button3"
android:background="@color/abc_search_url_text_normal"
android:textSize="@dimen/abc_text_size_title_material"
android:textStyle="bold"
android:theme="@android:style/Animation.Dialog"
android:layout_above="@+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="119dp" />
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/digitalClock"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#08041c"
android:textSize="@dimen/abc_action_bar_content_inset_material" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find"
android:id="@+id/button4"
android:layout_marginTop="97dp"
android:background="@color/abc_search_url_text_normal"
android:textSize="@dimen/abc_text_size_title_material"
android:textStyle="bold"
android:layout_below="@+id/digitalClock"
android:layout_alignRight="@+id/digitalClock"
android:layout_alignEnd="@+id/digitalClock" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other location"
android:id="@+id/button5"
android:layout_alignTop="@+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="@dimen/abc_text_size_title_material"
android:textStyle="bold"
android:background="@color/abc_search_url_text_normal" />
</RelativeLayout>