转载自android.tgbus.com/Android/tutorial/201104/349972.shtml
显示网页:
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
显示地图:
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);
从google搜索内容
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);
路径规划:
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);
拨打电话:
调用拨号程序 Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
Uri uri = Uri.parse("tel.xxxxxx");
Intent it =new Intent(Intent.ACTION_CALL,uri);
要使用这个必须在配置文件中加入
发送SMS/MMS:
调用发送短信的程序 Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "The SMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);
发送短信 Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
发送彩信 Uri uri = Uri.parse("content://media/external/images/media/23");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra("sms_body", "some text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/png");
startActivity(it);
发送Email
Uri uri = Uri.parse("mailto:xxx@abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it, "Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"me@abc.com"};
String[] ccs={"you@abc.com"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it, "Choose Email Client"));
添加附件
Intent it= new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));
播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
Uninstall 程序 Uri uri = Uri.fromParts("package", strPackageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);
sdk 文档 android_sdk/docs/guide/appendix/g-app-intents.html
打开照相机
<1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
this.sendBroadcast(i);
<2>long dateTaken = System.currentTimeMillis();
String name = createName(dateTaken) + ".jpg";
fileName = folder + name;
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, fileName);
values.put("_data", fileName);
values.put(Images.Media.PICASA_ID, fileName);
values.put(Images.Media.DISPLAY_NAME, fileName);
values.put(Images.Media.DESCRIPTION, fileName);
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
Uri photoUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(inttPhoto, 10);
从Gallery选取图像
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 11);
打开录音机
Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
startActivity(mi);
显示应用详细列表
Uri uri = Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
/ /by clicking on your application on Market home
//page, and notice the ID from the address bar
刚才找app id未果,结果发现用package name也可以
Uri uri = Uri.parse("market://details?id=");
这个简单多了
寻找应用
Uri uri = Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
打开联系人列表
<1>方法一
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("vnd.android.cursor.item/phone");
startActivityForResult(i, REQUEST_TEXT);
<2>方法二
Uri uri = Uri.parse("content://contacts/people");
Intent it = new Intent(Intent.ACTION_PICK, uri);
startActivityForResult(it, REQUEST_TEXT);
打开另一程序
Intent i = new Intent();
ComponentName cn = new ComponentName("com.yellowbook.android2",
"com.yellowbook.android2.AndroidSearch");
i.setComponent(cn);
i.setAction("android.intent.action.MAIN");
startActivityForResult(i, RESULT_OK);
调用android自带的图片浏览器
方法一
Java code
File file=newFile("/sdcard/IMG/1.jpg");
Intent it=newIntent(Intent.ACTION_VIEW);
Uri mUri=Uri.parse("file://"+file.getPath());
it.setDataAndType(mUri,"image/*");
startActivity(it);
方法二Java code
ComponentName componentName=newComponentName("com.cooliris.media","com.cooliris.media.Gallery"); Intent intent=newIntent();
intent.setComponent(componentName);
File file=newFile("/sdcard/IMG/1.jpg");
Uri mUri=Uri.parse("file://"+file.getPath());
intent.setData(mUri);
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
调用android自带录音软件
Intent intent = new Intent("android.provider.MediaStore.RECORD_SOUND");
startActivityForResult(intent, 0);
调用android系统自带的程序安装器安装程序
Intent intent = new Intent(Intent.ACTION_VIEW);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//filePath为文件路径
intent.setDataAndType(Uri.parse("file://"+filePath), "application/vnd.android.packagearchive");
startActivity(intent);
调用android自带播放器播放音乐
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri, MimeType);
startActivity(intent);
调用android自带视频播放
Android中除了利用VideoView播放视频文件外,还可以用发送Intent来调用视频播放模块。方法如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent(Intent.ACTION_VIEW);
String type = "video/mp4";
Uri name = Uri.parse("file:///sdcard/test.mp4");
intent.setDataAndType(name, type);
intent.setClassName("com.cooliris.media", "com.cooliris.media.MovieView");
startActivity(intent);
}
代码中的intent.setClassName("com.cooliris.media", "com.cooliris.media.MovieView"); 一句是选择合适的视频播放器,如果没有这一句,当Android中有多个视频播放器时可能会弹出个选择框,添加上这一句直接进入选择的媒体播放器。不同的媒体播放器存放的位置也有所不同,查找播放器位置较为简单的方法为点击视频文件并选取所需的媒体播放器的同时查看Log信息,在Log信息中查看视频播放器的位置,填上去就可以了。
这种方法对于只要求打开并播放视频文件的应用是可以的,但如果需要对播放器进行控制还是用VideoView的好些,相对来说VideoView容易控制。
调用android系统自带浏览器
方法1:
Uri uri = Uri.parse("http://blog.csdn.net/u0fly");
Intent it =newIntent(Intent.ACTION_VIEW,uri);
startActivity(it);
方法2:
Intent mIntent =newIntent();ComponentName comp =newComponentName("com.android.browser","com.android.browser.BrowserActivity");mIntent.setComponent(comp);
mIntent.setAction("android.intent.action.MAIN");
startActivity(mIntent);
方法1可以指定打开的页面。
还有一种方法是在当前程序的窗口中以WebView的形式打开一个网页
注意:需要在AndroidManifest.xml中添加
main.xml
android:layout_height="fill_parent" android:id="@+id/wv" />
主程序:
final Activity activity = this;
WebView wv=(WebView)this.findViewById(R.id.wv);
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
wv.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
wv.loadUrl("http://www.google.com");