2016-08-11 3 views
0

Ich bin neu in Android und habe Probleme beim Teilen von Bildern durch Freigabeabsicht. Ich habe viel gegoogelt, verschiedene Dinge ausprobiert, konnte aber immer noch keine Lösung finden.Android Share Intent Bildfreigabe funktioniert nicht

Mein Code ist:

  Intent shareIntent = new Intent(Intent.ACTION_SEND); 
      shareIntent.setType("image/*"); 
      shareIntent.putExtra(Intent.EXTRA_STREAM,uri); 
      this.startActivityForResult(Intent.createChooser(shareIntent,"Share with"),12); 

ich die uri geprüft haben, gespeichert die Datei eine Bitmap und seine Rückkehr Datei. Aber das Bild, das während des Teilens angezeigt wird, ist nicht gültig. Gmail sagt, dass der Anhang nicht angehängt werden konnte. Die Nachrichten-App konnte das Bild nicht laden.

Textfreigabe funktioniert gut.

Grundsätzlich schreibe ich ein Plugin für Unity. Hier ist mein Code für die Einheit Side:

string destination = Path.Combine(Application.persistentDataPath,"sharingImage" + ".png"); 
      if (!File.Exists(destination)) { 
       print("creating new file"); 
       File.Create(destination); 
      } 
      File.WriteAllBytes(destination, bytes); 

      print("destination= "+destination); 

      AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); 
      AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse","file://" + destination); 

      using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.kashiftasneem.sharelib.ShareController")) { 

       AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
       AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); 

       pluginClass.CallStatic("Share",message,uriObject,jo,gameObject.name,destination); 
      } 

I Ziel und uri bin angemeldet haben, sind sie:

destination = /data/data/com.kashiftasneem.shareandroidplugin2/files/sharingImage.png

uri = Datei: ///data/data/com.kashiftasneem.shareandroidplugin2/files/sharingImage.png

Antwort

0
Intent shareIntent = new Intent(); 
shareIntent.setAction(Intent.ACTION_SEND); 
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage); 
shareIntent.setType("image/jpeg"); 
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))); 

Es könnte helfen.

+0

nops hat nicht funktioniert. – kashif789us

+0

Ich denke, es könnte ein Problem mit URI sein. – Singh

+0

Ich habe die Frage bearbeitet, um weitere Informationen zu URI hinzuzufügen. – kashif789us

0

Versuchen Sie diesen Code:

 Bitmap bitmap = getBitmapFromView(idForSaveView); 
     try { 
      File file = new File(this.getExternalCacheDir(), "appdiam.png"); 
      FileOutputStream fOut = new FileOutputStream(file); 
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
      fOut.flush(); 
      //fOut.close(); 
      file.setReadable(true, false); 
      final Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); 
      intent.setType("image/png"); 
      startActivity(Intent.createChooser(intent, "Share image via")); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     }