请问,做Android微信分享和QQ分享图片功能必须要申请APPID吗,听说IOS不用,有没有知道详情的,解释一下,谢谢
问题点:
1. 做Android微信分享和QQ分享图片功能是不是必须要申请APPID,有没有不用APPID的方法?
2. 从官网看到IOS和Android都需要APPID,但朋友说IOS可以不用,有没有知道原因的,解释一下。
你朋友忽悠你的,按照官网上来做
给你推荐一个去百度搜索mob这个平台的分享和登录集成简单 使用也很简单 appid 是都需要的
public class ShareUtil {
public static final String PACKAGE_WECHAT = "com.tencent.mm";
public static final String PACKAGE_MOBILE_QQ = "com.tencent.mobileqq";
public static final String PACKAGE_QZONE = "com.qzone";
public static final String PACKAGE_SINA = "com.sina.weibo";
public static final String AUTHORITY = "com.ume.browser.fileprovider";
private static String sharePicName = "share_pic.jpg";
private static String sharePicPath = Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator+"UmeBrowser"+File.separator+"sharepic"+File.separator;
// 判断是否安装指定app
public static boolean isInstallApp(Context context, String app_package){
final PackageManager packageManager = context.getPackageManager();
List<PackageInfo> pInfo = packageManager.getInstalledPackages(0);
if (pInfo != null) {
for (int i = 0; i < pInfo.size(); i++) {
String pn = pInfo.get(i).packageName;
if (app_package.equals(pn)) {
return true;
}
}
}
return false;
}
/**
* 直接分享纯文本内容至QQ好友
* @param mContext
* @param content
*/
public static void shareQQ(Context mContext, String content) {
if (isInstallApp(mContext,PACKAGE_MOBILE_QQ)) {
Intent intent = new Intent("android.intent.action.SEND");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, content);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity"));
mContext.startActivity(intent);
} else {
Toast.makeText(mContext, "您需要安装QQ客户端", Toast.LENGTH_LONG).show();
}
}
/**
* 分享图片给QQ好友
*
* @param bitmap
*/
public void shareImageToQQ(Context mContext, Bitmap bitmap) {
if (isInstallApp(mContext,PACKAGE_MOBILE_QQ)) {
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.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("image/*");
// 遍历所有支持发送图片的应用。找到需要的应用
ComponentName componentName = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
shareIntent.setComponent(componentName);
// mContext.startActivity(shareIntent);
mContext.startActivity(Intent.createChooser(shareIntent, "Share"));
} catch (Exception e) {
// ContextUtil.getInstance().showToastMsg("分享图片到**失败");
}
}
}
/**
* 直接分享图片到微信好友
* @param context
* @param picFile
*/
public static void shareWechatFriend(Context context,String content ,File picFile){
if (isInstallApp(context,PACKAGE_WECHAT)){
Intent intent = new Intent();
ComponentName cop = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareImgUI");
intent.setComponent(cop);
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
if (picFile != null) {
if (picFile.isFile() && picFile.exists()) {
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(context, AUTHORITY, picFile);
} else {
uri = Uri.fromFile(picFile);
}
intent.putExtra(Intent.EXTRA_STREAM, uri);
// intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri);
}
}
// intent.putExtra("Kdescription", !TextUtils.isEmpty(content) ? content : "");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(intent);
context.startActivity(Intent.createChooser(intent, "Share"));
}else{
Toast.makeText(context, "您需要安装微信客户端", Toast.LENGTH_LONG).show();
}
}
/**
* 直接分享文本到微信好友
*
* @param context 上下文
*/
public static void shareWechatFriend(Context context, String content) {
if (isInstallApp(context,PACKAGE_WECHAT)) {
Intent intent = new Intent();
ComponentName cop = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");
intent.setComponent(cop);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra("android.intent.extra.TEXT", content);
// intent.putExtra("sms_body", content);
intent.putExtra("Kdescription", !TextUtils.isEmpty(content) ? content : "");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
Toast.makeText(context, "您需要安装微信客户端", Toast.LENGTH_LONG).show();
}
}
}
你可以看一下MobTech他们家有一个ShareSDK,可以客服问他一下他们。其实申请不难,我以前用过他们的这个产品。有文档,5分钟搞定的事。