2016-05-21 5 views
0

ich eine App bin erstellen, wo ich Bilder und vedio in Social-Media-schicken apps facebook g + funktioniert einwand aber whatsapp und twitter funktionieren nicht ich diesen Code verwendenwhatsapp und Twitter ist keine Bilder in android app bekommen

Code ist für whatsapp

Button whtsapp_sahre = (Button)dialog.findViewById(R.id.whatsapp_btn); 
    whtsapp_sahre.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Uri imageUri = Uri.parse("android.resource://\" + getPackageName() + \"/drawable/pic8"); 
      Intent shareIntent = new Intent(); 
      shareIntent.setAction(Intent.ACTION_SEND); 
      //Target whatsapp: 
      shareIntent.setPackage("com.whatsapp"); 
      //Add text and then Image URI 
      shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello"); 
      shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); 
      shareIntent.setType("image/*"); 
      shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
       try{ 
      startActivity(shareIntent); 
      } catch (android.content.ActivityNotFoundException ex) { 
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp"))); 
      } 
     } 
    }); 

und twitter-Code ist

Button _Twwiterbtn = (Button) dialog.findViewById(R.id.twwiter_btn); 
    _Twwiterbtn.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent shareIntent = new Intent(); 
      shareIntent.setAction(Intent.ACTION_SEND); 
      shareIntent.putExtra(Intent.EXTRA_STREAM,R.drawable.pic8); 
      shareIntent.putExtra(Intent.EXTRA_TITLE,"HELLO status"); 
      shareIntent.setType("image/*") 
        .setPackage("com.twitter.android"); 
      try { 
       startActivity(shareIntent); 
      } catch (android.content.ActivityNotFoundException ex) { 
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.twitter.android&hl=en"))); 
      } 
     } 
    }); 

bitte helfen dank

Antwort

0

diesen Code versuchen, seine Hilfe, die Sie zuerst Ihren Weg falsch sein kann

Code für whatsapp

String imagePath =Environment.getExternalStorageDirectory() + "/img.jpg"; 
    File f=new File(imagePath); 
    Uri uri = Uri.fromFile(f); 
    Intent share = new Intent(Intent.ACTION_SEND); 
    share.setPackage("com.whatsapp"); 
    share.setType("image/*"); 
    share.putExtra(Intent.EXTRA_TEXT,"testing text"); 
    share.putExtra(Intent.EXTRA_STREAM, uri); 
    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    startActivity(share); 

und Code für twitter

 String imagePath = Environment.getExternalStorageDirectory() 
          + "/img.jpg"; 
      File f=new File(imagePath); 
      Uri uri = Uri.fromFile(f); 
      Intent share = new Intent(Intent.ACTION_SEND); 
      share.setPackage("com.twitter.android"); 
      share.putExtra(Intent.EXTRA_TEXT, "Hello Amit Basliyal"); 
      share.putExtra(Intent.EXTRA_STREAM, uri); 
      share.setType("image/*"); 
      share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
      startActivity(share); 

kann Ihnen helfen, danke

Verwandte Themen