Android共享意图为facebook-分享文本和链接

问题描述:

我想使用Android共享意图在Facebook上发布的东西。它看起来像这样:Android共享意图为facebook-分享文本和链接

shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
shareIntent.setType("text/plain"); 
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Free education for all! http://linkd.in/xU8mCc"); 
startActivity(shareIntent); 

所以我的文章有两个 - 一些文字和链接。但是当消息发布在Facebook上时,它只有链接,没有消息。我尝试过各种附加功能,但没有任何效果

任何人都面临这个问题,并解决了它?我有facebook应用程序版本1.8.1

编辑:我试图删除链接,facebook应用程序不会将我的消息(显示一条空白消息张贴),但不是相反的方式。所以看起来应用程序完全忽略了任何纯文本消息。我吓坏了!这是在fb应用程序的一个主要的错误,短信不能发布(共享意图)?

+0

你好GreenBee我有同样的问题,这个代码共享图像,视频,链接和文本在Facebook上,但这个环节是不是现在打开[这是我的问题](http:// *。com/questions/14001859 /无法共享文本与链接通过Android共享意图)请帮助我如何解决这个问题 – Jeetu 2012-12-24 14:29:51

+0

这是我的解决方案,它工作正常,只是为了共享URL, http://*.com/a/29529335/513413 – Hesam 2015-04-09 03:41:52

如果您打算使用常规的Android共享内容,那么不幸的是,Facebook共享意图只能使用一个URL(确保它具有http://)并且没有其他文本消息。这是一个奇怪的限制,没有任何意义。

您必须在您的项目中使用官方独立的Facebook Android SDK才能获得完整的共享功能。这是额外的工作。

我跑到类似的问题。最后,我所做的是分支的意图。如果他们选择通过Facebook共享(在常规Android共享意图中),则创建一个新的共享意向,只有该URL并将其推送到Facebook。所有其他的股票期权(推特,消息,电子邮件)将正常工作。

我的问题和解决方案在这里:

Branching the Android Share Intent extras depending on which method they choose to share

String shareBody = "app string text " + act_txt + " more text! Get the app at http://www.appurl.com"; 

PackageManager pm = view.getContext().getPackageManager(); 
List<ResolveInfo> activityList = pm.queryIntentActivities(sharingIntent, 0); 
for(final ResolveInfo app : activityList) { 
    Log.i(TAG, "app.actinfo.name: " + app.activityInfo.name); 
    //if((app.activityInfo.name).contains("facebook")) { 
      if("com.facebook.katana.ShareLinkActivity".equals(app.activityInfo.name)) { 


     sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://www.appurl.com"); 
     startActivity(Intent.createChooser(sharingIntent, "Share idea")); 
     break; 
    } else { 
     sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "app name"); 
     sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); 
     startActivity(Intent.createChooser(sharingIntent, "Share")); 
     break; 
    } 
} 
+0

感谢您的想法。但是,为什么你总是在'for'循环中'break'呢? – 2017-09-22 17:58:13

+0

nvm,我明白了为什么... – 2017-09-22 18:04:17

我刚刚建立了这个代码和它的工作对我来说:

private void shareAppLinkViaFacebook(String urlToShare) { 
    try { 
     Intent intent1 = new Intent(); 
     intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler"); 
     intent1.setAction("android.intent.action.SEND"); 
     intent1.setType("text/plain"); 
     intent1.putExtra("android.intent.extra.TEXT", urlToShare); 
     startActivity(intent1); 
    } catch (Exception e) { 
     // If we failed (not native FB app installed), try share through SEND 
     String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare; 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl)); 
     startActivity(intent); 
    } 
} 
+5

似乎尝试{}功能不起作用,虽然我的设备上安装了Facebook应用程序,但捕获工作正常。 – Hesam 2015-04-08 10:12:53

+0

这里的信息在哪里? – mklimek 2016-01-12 14:56:27

+1

intent1.setPackage(“com.facebook.katana”);使用它而不是intent1.setClassName(“com.facebook.katana”,“com.facebook.katana.activity.composer.ImplicitShareIntentHandler”); – 2016-12-28 05:27:54

在我的应用我已经整合Facebook的SDK来使用户可以在他们的墙上分享报价[预填充文本]。使用FB SDK,可以做到这一点。它可以在我的应用程序中运行,并且我有超过5K的用户使用它。

显然这不符合FB的政策,因为我没有任何警告或问题,这没有奏效。

为同一代码片段可以在这里找到,

Do any widely used Android apps have Facebook sharing with pre-populated text field?

在棒棒堂(21),你可以使用Intent.EXTRA_REPLACEMENT_EXTRAS覆盖特定应用程序的意图。

https://developer.android.com/reference/android/content/Intent.html#EXTRA_REPLACEMENT_EXTRAS

private void doShareLink(String text, String link) { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    Intent chooserIntent = Intent.createChooser(shareIntent, getString(R.string.share_via)); 

    // for 21+, we can use EXTRA_REPLACEMENT_EXTRAS to support the specific case of Facebook 
    // (only supports a link) 
    // >=21: facebook=link, other=text+link 
    // <=20: all=link 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    shareIntent.putExtra(Intent.EXTRA_TEXT, text + " " + link); 
    Bundle facebookBundle = new Bundle(); 
    facebookBundle.putString(Intent.EXTRA_TEXT, link); 
    Bundle replacement = new Bundle(); 
    replacement.putBundle("com.facebook.katana", facebookBundle); 
    chooserIntent.putExtra(Intent.EXTRA_REPLACEMENT_EXTRAS, replacement); 
    } else { 
    shareIntent.putExtra(Intent.EXTRA_TEXT, link); 
    } 

    chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(chooserIntent); 
} 
+0

为什么我们不能在棒棒糖之前分享(文本和链接)? – 2017-06-08 22:46:57

使用perfectally工作

public class Shareonwall extends AppCompatActivity 
     implements NavigationView.OnNavigationItemSelectedListener { 

    JSONObject response, profile_pic_data, profile_pic_url; 
    TextView user_name, user_email; 
    ImageView user_picture; 
    NavigationView navigation_view; 
    CallbackManager callbackManager; 
    ShareDialog shareDialog; 
    int REQUEST_CAMERA = 0, SELECT_FILE = 1; 

    private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200; 
    private Uri fileUri; 
    // public static TextView output; 

    private static final int MY_PERMISSIONS_REQUEST_CAMERA = 110; 

    private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 222; 
    private static final int MY_PERMISSIONS_REQUEST_CAMERA_VIDEO = 333; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     facebookSDKInitialize(); 
     setContentView(R.layout.activity_details); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     Button button = (Button) findViewById(R.id.button); 
     Button imageShare = (Button) findViewById(R.id.imageShare); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setTitle("Home Page"); 

     Intent intent = getIntent(); 
     String jsondata = intent.getStringExtra("jsondata"); 

     setNavigationHeader(); // call setNavigationHeader Method. 
     setUserProfile(jsondata); // call setUserProfile Method. 


     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 
     shareDialog = new ShareDialog(this); // intialize facebook shareDialog. 

     navigation_view.setNavigationItemSelectedListener(this); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 


       if (ShareDialog.canShow(ShareLinkContent.class)) { 
        ShareLinkContent linkContent = new ShareLinkContent.Builder() 
          .setContentTitle("How to integrate Facebook from your app") 
          .setImageUrl(Uri.parse("http://www.devglan.com/image/dashboard.jpg")) 
          .setContentDescription(
            "simple Fb Image share integration") 
          .setContentUrl(Uri.parse("http://www.devglan.com/image/dashboard.jpg")) 
          .build(); 

        shareDialog.show(linkContent); // Show facebook ShareDialog 
       } 
      } 
     }); 

     imageShare.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       selectImage(); 
      } 
     }); 

    } 

    // this method is for create a dialog box to choose options to select Image to share on facebook. 
    private void selectImage() { 
     final CharSequence[] items = { "Take Photo", "Choose from Library","Record Video", 
       "Cancel" }; 

     AlertDialog.Builder builder = new AlertDialog.Builder(Shareonwall.this); 
     builder.setTitle("Select profile Photo!"); 
     builder.setItems(items, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int item) { 
       if (items[item].equals("Take Photo")) { 



        if (Build.VERSION.SDK_INT >= 23) { 
         if ((ContextCompat.checkSelfPermission(Shareonwall.this, 
           android.Manifest.permission.WRITE_EXTERNAL_STORAGE) 
           == PackageManager.PERMISSION_GRANTED) && (ContextCompat.checkSelfPermission(Shareonwall.this, 
           android.Manifest.permission.CAMERA) 
           == PackageManager.PERMISSION_GRANTED)) { 



          Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
          startActivityForResult(intent, REQUEST_CAMERA); 


         } else { 

          if ((ContextCompat.checkSelfPermission(Shareonwall.this, 
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE) 
            == PackageManager.PERMISSION_GRANTED) && (ContextCompat.checkSelfPermission(Shareonwall.this, 
            android.Manifest.permission.CAMERA) 
            == PackageManager.PERMISSION_GRANTED)) { 

           Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
           startActivityForResult(intent, REQUEST_CAMERA); 

          } else { 


           ActivityCompat.requestPermissions(Shareonwall.this, 
             new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.CAMERA}, 
             MY_PERMISSIONS_REQUEST_CAMERA); 
           Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
           startActivityForResult(intent, REQUEST_CAMERA); 


          } 

         } 
        } else { 

         Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
         startActivityForResult(intent, REQUEST_CAMERA);; 
        } 

       }  else if (items[item].equals("Choose from Library")) { 



        if (Build.VERSION.SDK_INT >= 23) { 
         if ((ContextCompat.checkSelfPermission(Shareonwall.this, 
           android.Manifest.permission.READ_EXTERNAL_STORAGE) 
           == PackageManager.PERMISSION_GRANTED)) { 

          Intent intent = new Intent(
            Intent.ACTION_PICK, 
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
          intent.setType("image/*"); 
          startActivityForResult(
            Intent.createChooser(intent, "Select File"), 
            SELECT_FILE); 
         } else { 

          if ((ContextCompat.checkSelfPermission(Shareonwall.this, 
            android.Manifest.permission.READ_EXTERNAL_STORAGE) 
            == PackageManager.PERMISSION_GRANTED)) { 


          } else { 


           ActivityCompat.requestPermissions(Shareonwall.this, 
             new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 
             MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); 


          } 

         } 
        } else { 
         Intent intent = new Intent(
           Intent.ACTION_PICK, 
           android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
         intent.setType("image/*"); 
         startActivityForResult(
           Intent.createChooser(intent, "Select File"), 
           SELECT_FILE); 
        } 


       } if (items[item].equals("Record Video")) { 


        if (Build.VERSION.SDK_INT >= 23) { 
         if ((ContextCompat.checkSelfPermission(Shareonwall.this, 
           android.Manifest.permission.READ_EXTERNAL_STORAGE) 
           == PackageManager.PERMISSION_GRANTED)) { 

          Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
          if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { 
           startActivityForResult(takeVideoIntent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); 
          } 
         } else { 

          if ((ContextCompat.checkSelfPermission(Shareonwall.this, 
            android.Manifest.permission.READ_EXTERNAL_STORAGE) 
            == PackageManager.PERMISSION_GRANTED)) { 


          } else { 


           ActivityCompat.requestPermissions(Shareonwall.this, 
             new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 
             MY_PERMISSIONS_REQUEST_CAMERA_VIDEO); 


          } 

         } 
        } else { 
         Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
         if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { 
          startActivityForResult(takeVideoIntent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); 
         } 
        } 


       } else if (items[item].equals("Cancel")) { 
        dialog.dismiss(); 
       } 
      } 
     }); 
     builder.show(); 
    } 


    @Override 
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     callbackManager.onActivityResult(requestCode, resultCode, data); 

     if (resultCode == Activity.RESULT_OK) { 

      if (requestCode == SELECT_FILE){ 

       onSelectFromGalleryResult(data); 


      } 

      else if (requestCode == REQUEST_CAMERA){ 

       onCaptureImageResult(data); 

      } 
      if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) { 
       // Uri videoUri = data.getData(); 
       // mVideoView.setVideoURI(videoUri); 
       // recordVideo(videoUri); 
       String selectedVideoFilePath = GetFilePathFromDevice.getPath(this, data.getData()); 
       final byte[] datas; 
       try { 
        datas = readBytes(selectedVideoFilePath,data.getData()); 
        PostVideo(datas, selectedVideoFilePath); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 

      } 

     } 
    } 
    public byte[] readBytes(String dataPath,Uri uri) throws IOException { 
     InputStream inputStream = new FileInputStream(dataPath); 
     ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); 
     byte[] buffer = new byte[1024]; 
     int len; 
     while ((len = inputStream.read(buffer)) != -1) { 
      byteBuffer.write(buffer, 0, len); 
     } 
     ShareDialogVideo(uri); 
     return byteBuffer.toByteArray(); 
    } 
    public void PostVideo(byte[] VideoBytes, String filePath) { 
     String url; 
     url = "/me/videos"; 

     AccessToken token = AccessToken.getCurrentAccessToken(); 
     if (token != null) { 
      Bundle param = new Bundle(); 
      param.putByteArray("video." + getFileExt(filePath), VideoBytes); 
      param.putString("description", "sample video"); 
      new GraphRequest(token,url, param, HttpMethod.POST, new GraphRequest.Callback() { 

       public void onCompleted(GraphResponse response) { 
        Log.e("New Post", "Res =" + response.toString()); 
        // dialog.dismiss(); 

        if (response != null && response.getJSONObject() != null && response.getJSONObject().has("id")) { 
         Log.e("New Post", "Success"); 
         Toast.makeText(Shareonwall.this, "Video posted successfully.", Toast.LENGTH_SHORT).show(); 
        } else { 
         Toast.makeText(Shareonwall.this, "Error in posting Video.", Toast.LENGTH_SHORT).show(); 
        } 
        setResult(Activity.RESULT_OK, new Intent()); 
        finish(); 
       } 
      }).executeAsync(); 
     } 
    } 
    public static String getFileExt(String fileName) { 
     return fileName.substring((fileName.lastIndexOf(".") + 1), fileName.length()); 
    } 

    /**** this method used for select image From Gallery *****/ 


    private void onSelectFromGalleryResult(Intent data) { 
     Uri selectedImageUri = data.getData(); 
     String[] projection = { MediaStore.MediaColumns.DATA }; 
     Cursor cursor = managedQuery(selectedImageUri, projection, null, null, 
       null); 
     int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); 
     cursor.moveToFirst(); 

     String selectedImagePath = cursor.getString(column_index); 

     Bitmap thumbnail; 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeFile(selectedImagePath, options); 
     final int REQUIRED_SIZE = 200; 
     int scale = 1; 
     while (options.outWidth/scale/2 >= REQUIRED_SIZE 
       && options.outHeight/scale/2 >= REQUIRED_SIZE) 
      scale *= 2; 
     options.inSampleSize = scale; 
     options.inJustDecodeBounds = false; 
     thumbnail = BitmapFactory.decodeFile(selectedImagePath, options); 

     ShareDialog(thumbnail); 
    } 

    /*** this method used for take profile photo *******/ 

    private void onCaptureImageResult(Intent data) { 
     Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); 
     ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
     thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes); 

     File destination = new File(Environment.getExternalStorageDirectory(), 
       System.currentTimeMillis() + ".jpg"); 

     FileOutputStream fo; 
     try { 
      destination.createNewFile(); 
      fo = new FileOutputStream(destination); 
      fo.write(bytes.toByteArray()); 
      fo.close(); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     ShareDialog(thumbnail); 
    } 



    // This method is used to share Image on facebook timeline. 
    public void ShareDialog(Bitmap imagePath){ 

     SharePhoto photo = new SharePhoto.Builder() 
       .setBitmap(imagePath) 
       .setCaption("Testing") 
       .build(); 
     SharePhotoContent content = new SharePhotoContent.Builder() 
       .addPhoto(photo) 
       .build(); 

     shareDialog.show(content); 

    } 
    public void ShareDialogVideo(Uri imagePath){ 

     ShareVideo shareVideo = new ShareVideo.Builder() 
       .setLocalUrl(imagePath) 
       .build(); 
     ShareVideoContent content = new ShareVideoContent.Builder() 
       .setVideo(shareVideo) 
       .build(); 
     shareDialog.show(content); 

    } 


    // Initialize the facebook sdk and then callback manager will handle the login responses. 

    protected void facebookSDKInitialize() { 

     FacebookSdk.sdkInitialize(getApplicationContext()); 

     callbackManager = CallbackManager.Factory.create(); 
    } 


    @Override 
    public void onBackPressed() { 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     if (drawer.isDrawerOpen(GravityCompat.START)) { 
      drawer.closeDrawer(GravityCompat.START); 
     } else { 
      super.onBackPressed(); 
     } 
    } 

    /* 
     Set Navigation header by using Layout Inflater. 
    */ 

    public void setNavigationHeader(){ 

     navigation_view = (NavigationView) findViewById(R.id.nav_view); 

     View header = LayoutInflater.from(this).inflate(R.layout.nav_header_home, null); 
     navigation_view.addHeaderView(header); 

     user_name = (TextView) header.findViewById(R.id.username); 
     user_picture = (ImageView) header.findViewById(R.id.profile_pic); 
     user_email = (TextView) header.findViewById(R.id.email); 
    } 

    /* 
     Set User Profile Information in Navigation Bar. 
    */ 

    public void setUserProfile(String jsondata){ 

     try { 
      response = new JSONObject(jsondata); 
      user_email.setText(response.get("email").toString()); 
      user_name.setText(response.get("name").toString()); 
      profile_pic_data = new JSONObject(response.get("picture").toString()); 
      profile_pic_url = new JSONObject(profile_pic_data.getString("data")); 

      Picasso.with(this).load(profile_pic_url.getString("url")) 
        .into(user_picture); 

     } catch (Exception e){ 
      e.printStackTrace(); 
     } 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     // getMenuInflater().inflate(R.menu.home, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

    @SuppressWarnings("StatementWithEmptyBody") 
    @Override 
    public boolean onNavigationItemSelected(MenuItem item) { 
     // Handle navigation view item clicks here. 
     int id = item.getItemId(); 

     if (id == R.id.nav_camera) { 
      // Handle the camera action 
     } else if (id == R.id.nav_gallery) { 

     } else if (id == R.id.nav_slideshow) { 

     } else if (id == R.id.nav_manage) { 

     } else if (id == R.id.nav_share) { 

     } else if (id == R.id.nav_send) { 

     } 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     drawer.closeDrawer(GravityCompat.START); 
     return true; 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 

     // Logs 'install' and 'app activate' App Events. 
     AppEventsLogger.activateApp(this); 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 

     // Logs 'app deactivate' App Event. 
     AppEventsLogger.deactivateApp(this); 
    } 

    @Override 
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 
     super.onRequestPermissionsResult(requestCode, permissions, grantResults); 

     switch (requestCode) { 
      case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: { 
       // If request is cancelled, the result arrays are empty. 
       if (grantResults.length > 0 
         && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 


        Intent intent = new Intent(
          Intent.ACTION_PICK, 
          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
        intent.setType("image/*"); 
        startActivityForResult(
          Intent.createChooser(intent, "Select File"), 
          SELECT_FILE); 

       } else { 


       } 
       return; 
      } 

      case MY_PERMISSIONS_REQUEST_CAMERA: { 
       // If request is cancelled, the result arrays are empty. 
       if (grantResults.length > 0 
         && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { 


        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        startActivityForResult(intent, REQUEST_CAMERA); 

       } else { 


       } 
       return; 
      } 
      case MY_PERMISSIONS_REQUEST_CAMERA_VIDEO :{ 

       Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
       if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { 
        startActivityForResult(takeVideoIntent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); 

       } 



      } 



      // other 'case' lines to check for other 
      // permissions this app might request 
     } 
    } 


}