例如:要在app中直接分享图片到微信、来往等,而不调用他们的sdk
直接贴代码如下;
public void shareImage(Bitmap bitmap) { try { Uri uriToImage = Uri.parse(MediaStore.Images.Media.insertImage( mContext.getContentResolver(), bitmap, null, null)); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage); shareIntent.setType("image/*"); // 遍历所有支持发送图片的应用。找到需要的应用 PackageManager packageManager = mContext.getPackageManager(); List<ResolveInfo> resolveInfoList = packageManager .queryIntentActivities(shareIntent, PackageManager.GET_INTENT_FILTERS); ComponentName componentName = null; for (int i = 0; i < resolveInfoList.size(); i++) { if (TextUtils.equals( resolveInfoList.get(i).activityInfo.packageName, YouNeedAppPackageName)) { componentName = new ComponentName( resolveInfoList.get(i).activityInfo.packageName, resolveInfoList.get(i).activityInfo.name); break; } } // 已安装** if (null != componentName) { shareIntent.setComponent(componentName); mContext.startActivity(shareIntent); } else { ContextUtil.getInstance().showToastMsg("请先安装**"); } } catch (Exception e) { ContextUtil.getInstance().showToastMsg("分享图片到**失败"); } }
参考的文章如下:
android设置应用程序默认值
Android中有时打开一个文件,系统会弹出一个应用程序选择列表供你选择.如果你把某个应用程序设为默认值,则不会弹出选择框,而会直接调用该程序.
设置方法如下:
列入修改系统默认Launhcer但不是唯一的Launcher
PackageManager pm = getPackageManager();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.MAIN");
filter.addCategory("android.intent.category.HOME");
filter.addCategory("android.intent.category.DEFAULT");
Context context = getApplicationContext();
ComponentName component = new ComponentName(context.getPackageName(), TestReplaceHomeAppActivity.class.getName()); ComponentName[] components = new ComponentName[] {new ComponentName("com.android.launcher", "com.android.launcher.Launcher"), component};
pm.clearPackagePreferredActivities("com.android.launcher"); pm.addPreferredActivity(filter, IntentFilter.MATCH_CATEGORY_EMPTY, components, component);
Android 如何实现本地图片直接分享到微信、来往、QQ等,直接分享图片到指定应用
原文地址:http://blog.csdn.net/bwgang/article/details/44750837