您的位置:首页 > 移动开发 > Android开发

Android APP代码拨打电话、打开手机分享功能等隐式意图

2015-06-03 16:42 726 查看
Android APP拨打电话:

Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+110));

startActivity(intent);

}

Android APP打开电话薄:

Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);

startActivityForResult(intent, 2);

Android APP打开相机:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path)));

startActivityForResult(intent, 2);

Android APP打开相册:

Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.INTERNAL_CONTENT_URI);

startActivityForResult(intent, 2);

Android APP短信分享:

Intent sendIntent = new Intent(Intent.ACTION_VIEW);

sendIntent.putExtra("sms_body", "#短信分享#");

sendIntent.setType("vnd.android-dir/mms-sms");

startActivity(sendIntent);

打开手机的分享功能:

Intent sendIntent = new Intent(Intent.ACTION_SEND);

// sendIntent.setType("image/png");//图片

// File f = new File(Environment.getExternalStorageDirectory() + "/Pictures/2.png");

// Uri u = Uri.fromFile(f);

// sendIntent.putExtra(Intent.EXTRA_STREAM, u);

sendIntent.setType("text/plain");//文字

sendIntent.putExtra(Intent.EXTRA_SUBJECT, "#好友分享#");

// 自动添加的发送的具体信息

sendIntent.putExtra(Intent.EXTRA_TEXT, "我现在正在玩应用,一起加入吧!更多资讯详见:http://www.xx.com");

sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(Intent.createChooser(sendIntent, getTitle()));

打开应用商店进行评价:

Uri uri=Uri.parse("market://details?id=" + Activity.this.getPackageName());

Intent intent=new Intent(Intent.ACTION_VIEW, uri);

PackageManager pm = this.getPackageManager();

List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);

if(list.size()==0){

Toast.makeText(this, "还未安装软件商店", Toast.LENGTH_SHORT).show();

}else{

startActivity(intent);

}

创建桌面快捷图标:

//发送广播的意图,要创建快捷图标了
Intent intent = new Intent();
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
//快捷方式  要包含3个重要的信息 1,名称 2.图标 3.干什么事情
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "仔仔手机安全卫士");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
//桌面点击图标对应的意图。
Intent shortcutIntent = new Intent();
shortcutIntent.setAction("android.intent.action.MAIN");
shortcutIntent.addCategory("android.intent.category.LAUNCHER");
shortcutIntent.setClassName(getPackageName(), "com.zaizai.safty.MainActivity");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
sendBroadcast(intent);

需添加权限

com.android.launcher.permission.INSTALL_SHORTCUT


MIME TYPE对照表:http://tool.oschina.net/commons http://blog.sina.com.cn/s/blog_446cc66b0100ublv.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: