如何正确创建一个像Tez一样引用的Intent?

在我的应用程序中,我必须添加一个共享我的应用程序的意图。 我查看了Tez,它共享了应用程序图标以及包含超链接的文本。 怎么做到这一点? 在此处输入图像描述

 private void prepareShareIntent(Bitmap bmp) { Uri bmpUri = getLocalBitmapUri(bmp); // see previous remote images section // Construct share intent as described above based on bitmap Intent shareIntent = new Intent(); shareIntent = new Intent(); shareIntent.setPackage("com.whatsapp"); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_app) ); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/*"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, "Share Opportunity")); } private Uri getLocalBitmapUri(Bitmap bmp) { Uri bmpUri = null; File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = null; try { out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); try { out.close(); } catch (IOException e) { e.printStackTrace(); } bmpUri = Uri.fromFile(file); } catch (FileNotFoundException e) { e.printStackTrace(); } return bmpUri; } 

你可以尝试一下..

  Uri uri = Uri.fromFile(imageFile); Intent intent1 = new Intent(); intent1.setAction(Intent.ACTION_SEND); intent1.setType("image/*"); intent1.putExtra(android.content.Intent.EXTRA_SUBJECT, "App Name"); intent1.putExtra(Intent.EXTRA_TEXT, "Download the app from google play store now - "+ APP_STORE_URL); intent1.putExtra(Intent.EXTRA_STREAM, uri); try { startActivity(Intent.createChooser(intent1, "Share")); } catch (ActivityNotFoundException e) { Toast.makeText(getContext(), "please try again", Toast.LENGTH_SHORT).show(); } 

这将工作:将图像文件和文本框放在共享意图中

看起来您想要创建一个引用程序链接,尝试使用此 firebase服务。一旦准备好了引用者URL。创建一个意图如下共享它。

 Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_SUBJECT, subjectText); shareIntent.putExtra(Intent.EXTRA_HTML_TEXT, "Hey!Checkout this app "+ APP_STORE_URL); shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); startActivity(Intent.createChooser(shareIntent, "Invite Friends")); 

**注意:**如果您使用的是动态链接,则可以在社交元标记参数中添加您的应用图标

尝试这个

 Uri imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher"); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello" + REFERRAL_URL); shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); shareIntent.setType("image/jpeg"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, "send"));` 
 Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/jpeg"); /**This is the image to share**/ Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, "title"); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); OutputStream outstream; try { outstream = getContentResolver().openOutputStream(uri); icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream); outstream.close(); } catch (Exception e) { System.err.println(e.toString()); } share.putExtra(Intent.EXTRA_STREAM, uri); share.putExtra(Intent.EXTRA_TEXT, "YOUR_BODY_TEXT_HERE"); startActivity(Intent.createChooser(share, "Share Image")); 

我已经测试了上面的代码,它按照你的要求工作。

PS:您需要拥有WRITE_EXTERNAL_STORAGE权限。 请务必包含它并根据SDK进行处理。

此代码将共享两个文件

  ArrayList myFilesUriList = new ArrayList<>(); myFilesUriList.add(); // add your image path as uri myFilesUriList.add(); // add your text file path as uri Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.setType("image/*"); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, myFilesUriList); startActivity(intent); 
  This code will share both the files Separately First share the file then on Activity Result, share text Separately 
  ArrayList uriArrayList = new ArrayList<>(); uriArrayList.add(); // add your image path as uri Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.setType("image/*"); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriArrayList); startActivityForResult(intent, 156); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 156) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/*"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here" sharingIntent.putExtra(Intent.EXTRA_TEXT, "shareBody "); sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(Intent.createChooser(sharingIntent, "Share text via..")); } } 

这是URL元数据。 这些元数据作为服务器的响应返回。

       

在WhatsApp中显示链接的缩略图|| og:图像元标记不起作用

步骤1 – 读取您要共享的图像步骤2 – 将该图像存储在外部存储中步骤3 – 通过意图共享

 // Extract Bitmap from ImageView drawable Drawable drawable = ContextCompat.getDrawable(this, R.mipmap.launcher); // your image if (drawable instanceof BitmapDrawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); // Store image to default external storage directory Uri bitmapUri = null; try { File file = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png"); file.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bitmapUri = Uri.fromFile(file); } catch (IOException e) { e.printStackTrace(); } if (bitmapUri != null) { Intent shareIntent = new Intent(); shareIntent.putExtra(Intent.EXTRA_TEXT, "I am inviting you to join our app. A simple and secure app developed by us. https://www.google.co.in/"); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, bitmapUri); shareIntent.setType("image/*"); startActivity(Intent.createChooser(shareIntent, "Share my app")); } } 

注 – 在清单中添加WRITE_EXTERNAL_STORAGE权限。 在Android 6.0及更高版本上询问运行时权限。

您可能正在寻找与您的应用程序的深层链接

https://developer.android.com/training/app-links/index.html

https://developer.android.com/training/app-links/deep-linking.html

或者,如果您想要跨平台链接到您的应用,可以查看Firebase动态链接 https://firebase.google.com/docs/dynamic-links/

将此代码复制到工具栏/菜单中

  try { Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_SUBJECT, "Your Subject"); String text = "\nYour description"; text = text + "https://play.google.com/store/apps/details?id=apppackagename \n\n"; i.putExtra(Intent.EXTRA_TEXT, text); startActivity(Intent.createChooser(i, "Choose ")); } catch(Exception e) { //e.toString(); } 

试试这段代码:

 int applicationNameId = context.getApplicationInfo().labelRes; final String appPackageName = context.getPackageName(); Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_SUBJECT, activity.getString(applicationNameId)); String text = "Install this cool application: "; String link = "https://play.google.com/store/apps/details?id=" + appPackageName; i.putExtra(Intent.EXTRA_TEXT, text + " " + link); startActivity(Intent.createChooser(i, "Share link:")); 

如果你想从开发者那里分享你的其他应用程序。 帐户你可以做这样的事情

 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://play.google.com/store/apps/developer? id=Your_Publisher_Name")); startActivity(intent);