我看到我的书上有写android中有内置的activity供其他程序方便调用,其中一个其intent的action为ACTION_VIEW,uri是geo:0,0?q=street+address,可以显示要查询的位置地图,于是我写了如下的程序:
package com.test;import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.*;public class Location extends Activity {
private EditText addressfield;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addressfield = (EditText)findViewById(R.id.addressText);
Button showbutton = (Button)findViewById(R.id.showmap);
showbutton.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
String address = addressfield.getText().toString();
address = address.replace(' ', '+');
Intent gointent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + address));
startActivity(gointent);
}
});
}
}
但是运行是错误的,也没有显示地图,是我代码的问题还是因为我的android虚拟机中没有这个内置的activity?请高手解答
package com.test;import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.*;public class Location extends Activity {
private EditText addressfield;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addressfield = (EditText)findViewById(R.id.addressText);
Button showbutton = (Button)findViewById(R.id.showmap);
showbutton.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
String address = addressfield.getText().toString();
address = address.replace(' ', '+');
Intent gointent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + address));
startActivity(gointent);
}
});
}
}
但是运行是错误的,也没有显示地图,是我代码的问题还是因为我的android虚拟机中没有这个内置的activity?请高手解答
try {
startActivity(gointent);
} catch (Exception e) {
Log.d("go", "error" + ":" + e.toString());
}
然后,go标签下的Logcat提示是:03-06 02:28:15.769: DEBUG/go(349): error:android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=geo:0,0?q=Beijing }
这个意思是找不到可以处理该intent的activity吧,可是为什么会没有呢,书上讲有内置的,求解