【问题标题】:How to properly create an Intent to refer like Tez?如何正确创建一个像 Tez 一样引用的 Intent?
【发布时间】:2018-09-08 03:15:22
【问题描述】:

在我的应用程序中,我必须添加一个意图来共享我的应用程序。我查看了 Tez,它共享应用程序图标以及包含超链接的文本。如何做到这一点?

【问题讨论】:

  • 什么是Tez?它不是 Android SDK 的一部分。
  • 我不是说 tez 是 android sdk 的一部分,我的意思是他们是如何发送这个意图的
  • @VladyslavMatviienko Tez 是一款用于转账的谷歌应用程序。
  • 所有答案都不起作用。我都试过了。

标签: android android-intent invite


【解决方案1】:

你可以试试这个..

    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();
    }

这将起作用:将图像文件和文本框放入共享意图中

【讨论】:

    【解决方案2】:
    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;
        }
    

    【讨论】:

      【解决方案3】:

      您似乎想创建一个引荐来源链接,尝试使用this firebase 服务。一旦您准备好引荐来源网址。创建如下意图以共享它。

      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"));
      

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

      【讨论】:

        【解决方案4】:

        试试这个

        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"));`
        

        【讨论】:

          【解决方案5】:
          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 的处理它。

          【讨论】:

            【解决方案6】:

            此代码将共享这两个文件

                ArrayList<Uri> 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<Uri> 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.."));
            
                    }
                }
            

            【讨论】:

              【解决方案7】:

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

              <meta property="og:site_name" content="San Roque 2014 Pollos">
              <meta property="og:title" content="San Roque 2014 Pollos" />
              <meta property="og:description" content="Programa de fiestas" />
              <meta property="og:image" itemprop="image" content="http://pollosweb.wesped.es/programa_pollos/play.png">
              <meta property="og:type" content="website" />
              <meta property="og:updated_time" content="1440432930" />
              

              Showing Thumbnail for link in WhatsApp || og:image meta-tag doesn't work

              【讨论】:

                【解决方案8】:

                第 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 及更高版本上询问运行时权限。

                【讨论】:

                  【解决方案9】:

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

                  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/

                  【讨论】:

                    【解决方案10】:

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

                        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();
                    }
                    

                    【讨论】:

                      【解决方案11】:

                      试试这个代码:

                      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);
                      

                      【讨论】:

                        猜你喜欢
                        • 2023-01-29
                        • 2020-08-22
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 2019-01-18
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        相关资源
                        最近更新 更多