2016-06-22 5 views
1

unterstützt Ich versuche Bild zu teilen WhatsApp oder andere Anwendungen. Bild ist im aufklappbaren Ordner im androiden Studio. Aber wenn ich es versuche, tut es Toasts, dass das Dateiformat nicht unterstützt wird. Unten ist mein Code Hilfe Vielen Dank im VorausIch versuche, ein Bild zu senden, um WhatsApp aber es Toast erscheint und sagt die Datei Format nicht

public void share(View view) 
{ 
    Uri uri=Uri.parse("android.resource://com.faisal.home.myapplication/drawable/"+R.drawable.tease); 
    Intent intent,chooser; 
    intent=new Intent(Intent.ACTION_SEND); 
    intent.setType("image/*"); 
    intent.putExtra(Intent.EXTRA_STREAM,uri); 
    chooser=Intent.createChooser(intent,"share Image"); 
    if(intent.resolveActivity(getPackageManager())!=null) 
    { 
     startActivity(chooser); 

    } 
    else 
    { 

     Toast.makeText(this,"No app to share",Toast.LENGTH_LONG).show(); 
    } 


} 
+0

Bitte helfen ..... .Please !!!!!! – FaisalAhmed

Antwort

5
Try below mention code its working fine: 

try { 
        Uri imageUri = null; 
        try { 
         imageUri = Uri.parse(MediaStore.Images.Media.insertImage(Activity.getContentResolver(), 
           BitmapFactory.decodeResource(getResources(), R.drawable.yourimage), null, null)); 
        } catch (NullPointerException e) { 
        } 

        Intent shareIntent = new Intent(Intent.ACTION_SEND); 
        shareIntent.setType("*/*"); 
        shareIntent.putExtra(Intent.EXTRA_TEXT, "your text"); 

        shareIntent.putExtra(Intent.EXTRA_STREAM,imageUri); 

        startActivity(shareIntent); 
       } catch (android.content.ActivityNotFoundException ex) { 
        Toast.makeText(Activity, "no app fount", Toast.LENGTH_LONG).show(); 
       } 
+0

Danke .... Es funktioniert. erklären Können Sie mir bitte, was MediaStore.Images.Media.insertImage (Activity.getContentResolver(), BitmapFactory.decodeResource (GetResources(), R.drawable.yourimage tut? – FaisalAhmed

+0

seine Verwendung von Pfad Ihres ziehbar Bild bekommen –