Teilen png in drawable-Ordner

Ich bin die Integration von teilen mit den folgenden code für die app.

private void socialShare()
    {
        Uri uri = Uri.parse("android.resource://com.example.myproject/drawable/appicon");
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent.putExtra(Intent.EXTRA_TEXT, "sharing myapp");
        shareIntent.setType("image/jpeg");
        startActivity(Intent.createChooser(shareIntent, "Share from"));
    }

Wie im obigen code, ich versuchte png image die in den drawable Ordner. Das Bild ist aber nicht gesendet werden. Ist das, weil in setType, es ist image/jpeg? Ich kann nicht mit jpeg, da es verliert an Transparenz. Kann jemand bitte empfehlen Sie mir, wie zu teilen, mit Bild?

Hier ist der code, den ich verwenden, um das Bild zu kopieren aus dem drawable zu sdcard:

String commonPath = Environment.getExternalStorageDirectory().toString() + "/MyAppFolder"; 
        File direct = new File(commonPath);

        if(!direct.exists())
        {
            if(direct.mkdir()) 
              {
                Log.d("tag","directory created");
               //directory is created;
              }

        }

        Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.sharingimage);
        OutputStream outStream = null;
           File savingFile = new File(commonPath, "shareImage.png");
           if(!savingFile.exists())
           {
               Log.d("tag","file is created");

           try {
                savingFile.createNewFile();
                outStream = new FileOutputStream(savingFile);
                bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
                outStream.flush();
                outStream.close();

                Log.d("tag","Saved");

               } catch (FileNotFoundException e) {
                //TODO Auto-generated catch block
                e.printStackTrace();

               } catch (IOException e) {
                //TODO Auto-generated catch block
                e.printStackTrace();

               }

            }
InformationsquelleAutor rick | 2013-08-29
Schreibe einen Kommentar