当前位置: 编程技术>移动开发
本页文章导读:
▪回来home 回到home
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
......
▪ intent调用小结(转) intent调用总结(转)
显示Web网页: 1. Uri uri = Uri.parse("http://www.android123.com.cn"); 2. Intent it = new Intent(Intent.ACTION_VIEW,uri); 3. startActivity(it);显示Google地图: 1. Uri uri = Uri.parse("geo:38.899533,-77.0364.........
▪ 比值缩放图片 比例缩放图片
// load the origial BitMap (500 x 500 px)
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidt.........
[1]回来home
来源: 互联网 发布时间: 2014-02-18
回到home
Intent startMain = new Intent(Intent.ACTION_MAIN); startMain.addCategory(Intent.CATEGORY_HOME); startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(startMain);
[2] intent调用小结(转)
来源: 互联网 发布时间: 2014-02-18
intent调用总结(转)
显示Web网页:
1. Uri uri = Uri.parse("http://www.android123.com.cn");
2. Intent it = new Intent(Intent.ACTION_VIEW,uri);
3. startActivity(it);
显示Google地图:
1. Uri uri = Uri.parse("geo:38.899533,-77.036476");
2. Intent it = new Intent(Intent.Action_VIEW,uri);
3. startActivity(it);
Maps路径规划:
1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2. Intent it = new Intent(Intent.ACTION_VIEW,URI);
3. startActivity(it);
拨打电话:
1. Uri uri = Uri.parse("tel:xxxxxx");
2. Intent it = new Intent(Intent.ACTION_DIAL, uri);
3. startActivity(it);
1. Uri uri = Uri.parse("tel.xxxxxx");
2. Intent it =new Intent(Intent.ACTION_CALL,uri);
注意需要权限 <uses-permission id="android.permission.CALL_PHONE" />
发送SMS/MMS
1. Intent it = new Intent(Intent.ACTION_VIEW);
2. it.putExtra("sms_body", "android开发网欢迎您");
3. it.setType("vnd.android-dir/mms-sms");
4. startActivity(it);
发送短信
1. Uri uri = Uri.parse("smsto:10086");
2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
3. it.putExtra("sms_body", "10086"); //正文为10086
4. startActivity(it);
发送彩信
1. Uri uri = Uri.parse("content://media/external/images/media/10"); //该Uri根据实际情况修改,external代表外部存储即sdcard
2. Intent it = new Intent(Intent.ACTION_SEND);
3. it.putExtra("sms_body", "android123.com.cn");
4. it.putExtra(Intent.EXTRA_STREAM, uri);
5. it.setType("image/png");
6. startActivity(it);
发送Email
2. Uri uri = Uri.parse("mailto:android123@163.com");
3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
4. startActivity(it);
1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_EMAIL, "android123@163.com");
3. it.putExtra(Intent.EXTRA_TEXT, "android开发网测试");
4. it.setType("text/plain");
5. startActivity(Intent.createChooser(it, "选择一个Email客户端"));
1. Intent it=new Intent(Intent.ACTION_SEND);
2. String[] tos={"android123@163.com"}; //发送到
3. String[] ccs={"ophone123@163.com"}; //抄送
4. it.putExtra(Intent.EXTRA_EMAIL, tos);
5. it.putExtra(Intent.EXTRA_CC, ccs);
6. it.putExtra(Intent.EXTRA_TEXT, "正文");
7. it.putExtra(Intent.EXTRA_SUBJECT, "标题");
8. it.setType("message/rfc822"); //编码类型
9. startActivity(Intent.createChooser(it, "选择一个Email客户端"));
Email添加附件
1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_SUBJECT, "正文");
3. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/nobody.mp3"); //附件为sd卡上的nobody MP3文件
4. sendIntent.setType("audio/mp3");
5. startActivity(Intent.createChooser(it, "选择一个Email客户端"));
播放多媒体
1.
2. Intent it = new Intent(Intent.ACTION_VIEW);
3. Uri uri = Uri.parse("file:///sdcard/nobody.mp3");
4. it.setDataAndType(uri, "audio/mp3");
5. startActivity(it);
1. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); //从系统内部的MediaProvider索引中调用播放
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
Uninstall卸载程序
1. Uri uri = Uri.fromParts("package", packageName, null); //packageName为包名,比如com.android123.apkInstaller
2. Intent it = new Intent(Intent.ACTION_DELETE, uri);
3. startActivity(it);
进入联系人界面
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(People.CONTENT_URI);
startActivity(intent);
查看某个联系人,当然这里是ACTION_VIEW,如果为选择并返回action改为ACTION_PICK,当然处理intent时返回需要用到startActivityforResult
Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, ID);//最后的ID参数为联系人Provider中的数据库BaseID,即哪一行
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(personUri);
startActivity(intent);
选择一个图片
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, 0);
调用Android设备的照相机,并设置拍照后存放位置
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment
.getExternalStorageDirectory().getAbsolutePath()+"/cwj", android123 + ".jpg"))); //存放位置为sdcard卡上cwj文件夹,文件名为android123.jpg格式
startActivityForResult(intent, 0);
搜索指定package name在market上,比如搜索com.android123.cwj的写法如下
Uri uri = Uri.parse("market://search?q=pname:com.android123.cwj");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
显示Web网页:
1. Uri uri = Uri.parse("http://www.android123.com.cn");
2. Intent it = new Intent(Intent.ACTION_VIEW,uri);
3. startActivity(it);
显示Google地图:
1. Uri uri = Uri.parse("geo:38.899533,-77.036476");
2. Intent it = new Intent(Intent.Action_VIEW,uri);
3. startActivity(it);
Maps路径规划:
1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2. Intent it = new Intent(Intent.ACTION_VIEW,URI);
3. startActivity(it);
拨打电话:
1. Uri uri = Uri.parse("tel:xxxxxx");
2. Intent it = new Intent(Intent.ACTION_DIAL, uri);
3. startActivity(it);
1. Uri uri = Uri.parse("tel.xxxxxx");
2. Intent it =new Intent(Intent.ACTION_CALL,uri);
注意需要权限 <uses-permission id="android.permission.CALL_PHONE" />
发送SMS/MMS
1. Intent it = new Intent(Intent.ACTION_VIEW);
2. it.putExtra("sms_body", "android开发网欢迎您");
3. it.setType("vnd.android-dir/mms-sms");
4. startActivity(it);
发送短信
1. Uri uri = Uri.parse("smsto:10086");
2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
3. it.putExtra("sms_body", "10086"); //正文为10086
4. startActivity(it);
发送彩信
1. Uri uri = Uri.parse("content://media/external/images/media/10"); //该Uri根据实际情况修改,external代表外部存储即sdcard
2. Intent it = new Intent(Intent.ACTION_SEND);
3. it.putExtra("sms_body", "android123.com.cn");
4. it.putExtra(Intent.EXTRA_STREAM, uri);
5. it.setType("image/png");
6. startActivity(it);
发送Email
2. Uri uri = Uri.parse("mailto:android123@163.com");
3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
4. startActivity(it);
1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_EMAIL, "android123@163.com");
3. it.putExtra(Intent.EXTRA_TEXT, "android开发网测试");
4. it.setType("text/plain");
5. startActivity(Intent.createChooser(it, "选择一个Email客户端"));
1. Intent it=new Intent(Intent.ACTION_SEND);
2. String[] tos={"android123@163.com"}; //发送到
3. String[] ccs={"ophone123@163.com"}; //抄送
4. it.putExtra(Intent.EXTRA_EMAIL, tos);
5. it.putExtra(Intent.EXTRA_CC, ccs);
6. it.putExtra(Intent.EXTRA_TEXT, "正文");
7. it.putExtra(Intent.EXTRA_SUBJECT, "标题");
8. it.setType("message/rfc822"); //编码类型
9. startActivity(Intent.createChooser(it, "选择一个Email客户端"));
Email添加附件
1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_SUBJECT, "正文");
3. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/nobody.mp3"); //附件为sd卡上的nobody MP3文件
4. sendIntent.setType("audio/mp3");
5. startActivity(Intent.createChooser(it, "选择一个Email客户端"));
播放多媒体
1.
2. Intent it = new Intent(Intent.ACTION_VIEW);
3. Uri uri = Uri.parse("file:///sdcard/nobody.mp3");
4. it.setDataAndType(uri, "audio/mp3");
5. startActivity(it);
1. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); //从系统内部的MediaProvider索引中调用播放
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
Uninstall卸载程序
1. Uri uri = Uri.fromParts("package", packageName, null); //packageName为包名,比如com.android123.apkInstaller
2. Intent it = new Intent(Intent.ACTION_DELETE, uri);
3. startActivity(it);
进入联系人界面
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(People.CONTENT_URI);
startActivity(intent);
查看某个联系人,当然这里是ACTION_VIEW,如果为选择并返回action改为ACTION_PICK,当然处理intent时返回需要用到startActivityforResult
Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, ID);//最后的ID参数为联系人Provider中的数据库BaseID,即哪一行
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(personUri);
startActivity(intent);
选择一个图片
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, 0);
调用Android设备的照相机,并设置拍照后存放位置
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment
.getExternalStorageDirectory().getAbsolutePath()+"/cwj", android123 + ".jpg"))); //存放位置为sdcard卡上cwj文件夹,文件名为android123.jpg格式
startActivityForResult(intent, 0);
搜索指定package name在market上,比如搜索com.android123.cwj的写法如下
Uri uri = Uri.parse("market://search?q=pname:com.android123.cwj");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
[3] 比值缩放图片
来源: 互联网 发布时间: 2014-02-18
比例缩放图片
// load the origial BitMap (500 x 500 px) Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.android); int width = bitmapOrg.width(); int height = bitmapOrg.height(); int newWidth = 200; int newHeight = 200; // calculate the scale - in this case = 0.4f float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // createa matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the BitMap // to the ImageView, ImageButton or what ever BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); ImageView imageView = new ImageView(this); // set the Drawable on the ImageView imageView.setImageDrawable(bmd); // center the Image imageView.setScaleType(ScaleType.CENTER);
最新技术文章: