Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by M_Shazaib · Dec 14, 2018 at 01:33 PM · how-tomake

How can i make a ScreenShot and Share button in unity for AR(ARCORE)

I am making an AR app. I just want to add a share button before publishing it.. but I can't I tried so many methods but none work for AR(ARCORE) Plz tell me how to do it. I even bought some plugins but they don't seem to work in AR. ANY help will be appreciated.,I am really stuck on this part I have to publish today so plz help me out ASAP. ,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by petarpejovic · Dec 14, 2018 at 02:20 PM

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using System.IO;
  
 public class ShareScreenshot : MonoBehaviour {
   
  private bool isProcessing = false;
  public float startX;
  public float startY;
  public int valueX;
  public int valueY;
  
  
  
  public void shareScreenshot(){
  
   if(!isProcessing && GameObject.Find("Ask Friend").GetComponent<Image>().enabled)
    StartCoroutine( captureScreenshot() );
  }
  
  public IEnumerator captureScreenshot(){
   isProcessing = true;
   yield return new WaitForEndOfFrame();
   
   Texture2D screenTexture = new Texture2D(Screen.width*valueX/10000, Screen.height*valueY/10000,TextureFormat.RGB24,true);
  
   // put buffer into texture
   //screenTexture.ReadPixels(new Rect(0f, 0f, Screen.width, Screen.height),0,0);
   //create a Rect object as per your needs.
   screenTexture.ReadPixels(new Rect
                            (Screen.width*startX, (Screen.height*startY), Screen.width*valueX/10000, Screen.height*valueY/10000),0,0);
  
   // apply
   screenTexture.Apply();
  
   //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- PHOTO
  
   //byte[] dataToSave = Resources.Load<TextAsset>("everton").bytes;
   byte[] dataToSave = screenTexture.EncodeToPNG();
    
   string destination = Path.Combine(Application.persistentDataPath,System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png");
    
   File.WriteAllBytes(destination, dataToSave);
  
  
   if(!Application.isEditor)
   {
    // block to open the file and share it ------------START
    AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
    AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
    intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
    AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
    AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse","file://" + destination);
    intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
    intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "Which Football Club does this Rebus represent?\n" +
                                         "Download the game on play store at "+"\nhttps://play.google.com/store/apps/details?id=com.TGC.RebusFC&pcampaignid=GPC_shareGame");
    intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "Which club is this?");
    intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
    AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
     
    // option one WITHOUT chooser:
    currentActivity.Call("startActivity", intentObject);
     
    // block to open the file and share it ------------END
     
   }
   isProcessing = false;
  
  }
 }


  1. Create a C# script named ShareScreenshot and paste the below code to it:

    1. Attach the script to Main Camera or any object that is present on the scene.

    2. Call the shareScreenshot() method on click of a button.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image M_Shazaib · Dec 14, 2018 at 03:05 PM 0
Share

HI, Thanks for ur reply I tried this but nothing happens when the button is pressed. I called the on click as I said but nothing happens .. Have u tried this in a AR Project?

avatar image M_Shazaib · Dec 14, 2018 at 03:10 PM 0
Share

Gives out this error

NullReferenceException: Object reference not set to an instance of an object ShareScreenshot.shareScreenshot () (at Assets/_SCRIPTS/ShareScreenshot.cs:20)

avatar image petarpejovic · Dec 14, 2018 at 03:26 PM 0
Share

Try to delete && GameObject.Find("Ask Friend").GetComponent().enabled. It should work then. I forgot to delete it. Let me know if it works :)

avatar image M_Shazaib · Dec 14, 2018 at 06:24 PM 0
Share

I'll be home soon to try it... have u tried this before in AR?

avatar image M_Shazaib · Dec 14, 2018 at 07:43 PM 0
Share

alt text

Now it gives this error

capture.jpg (24.3 kB)
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make Glass 0 Answers

Detect system requirements 1 Answer

How to make a flame particle? 1 Answer

a few questions 2 Answers

how to remake a terrain flat ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges