2024年4月1日发(作者:)
Android如何实现本地图片直接分享到微信、来往、QQ等,
直接分享图片到指定应用-电脑资料
例如:要在app中直接分享图片到微信、来往等,而不调用他们
的sdk
直接贴代码如下;
public void shareImage(Bitmap bitmap) {
Uri uriToImage
null, bitmap,
try {
=
(Image(
tentResolver(),
null)); Intent shareIntent = new Intent();
ion(_SEND);
e("image/*");
ra(_STREAM, uriToImage);
// 遍历所有支持发送图片的应用,。找到需要的应用
PackageManager packageManager
=
kageManager();
List
.queryIntentActivities(shareIntent,
_INTENT_FILTERS);
ComponentName componentName = null;
for (int i = 0; i < (); i++) {
if ((
(i).eName,
YouNeedAppPackageName)) {
componentName
= new
ComponentName(
(i).eName,
败");
(i).);
break;
}
// 已安装**
if
(null
}
}
!=
componentName) {
ponent(componentName);
ctivity(shareIntent);
}
}
} catch (Exception e) {
else {
tance().showToastMsg("请先安装**");
tance().showToastMsg("分享图片到**失
}
参考的文章如下:
android设置应用程序默认值
Android中有时打开一个文件,系统会弹出一个应用程序选择列表
供你选择.如果你把某个应用程序设为默认值,则不会弹出选择框,而会直
接调用该程序.
设置方法如下:
PackageManager pm = getPackageManager();
IntentFilterfilter = new IntentFilter();
egory("T");
ComponentName
ppClassName");
ComponentName[]
ComponentName[]{new
ComponentName("YourPreferAppPakageName","YourPreferApp
ClassName"), component};
ackagePreferredActivities("YourClearAppPakageN
ame");
ferredActivity(filter,_CATEGOR
components = new
component =
newComponentName("YourClearAppPakageName","YourClearA
Y_EMPTY, components, component);
列入修改系统默认Launhcer但不是唯一的Launcher
/>PackageManager pm = getPackageManager();
IntentFilter filter = new IntentFilter();
de> ion(""); egory("");
egory("
T");
Context context = getApplicationContext();
ComponentName
TestReplaceHomeAppActivi component = new ComponentName(kageName(), />e()); ComponentName[] components = new ComponentName[] {new ComponentName("er", "er"), component}; />ivities("er"); ferredActivity(filter, _CATEGORY_EMPTY, component); 修改默认浏览器 PackageManager =kageManager(); "T"; "BLE"; ""; //设置默认项的必须参数之一,用户的操作符合该过滤器时,默认设 String String String packageManager str1 str2 str3 = = = components, 置起效 IntentFilter filter = new IntentFilter(str3); egory(str1); ComponentName ComponentName(context e()); component egory(str2); = new aScheme("http"); //设置浏览页面用的Activity .getPackageName(), Intent intent = new Intent(str3); egory(str2); egory(str1); Uri uri = (""); aAndType(uri, null); //找出手机当前安装的所有浏览器程序 List resolveInfoList = packageManager int = 0; size i < = .queryIntentActivities(intent, (); size; i++) { ComponentName[] activityInfo = 置 = } _INTENT_FILTERS); arrayOfComponentName = newComponentName[size]; for (int i ActivityInfo String 的默 =(i).activityInfo; // ); 清除之前 packageName 认设 eName; String className = ; ackagePreferredActivities(packageName ComponentName = componentName componentName; newComponentName(packageName, arrayOfComponentName[i] ferredActivity(filter, _CATEGORY_SCHEME,arrayOfComponentNa me, component); className); ackagePreferredAct


发布评论