2016-05-04 2 views
0

私は以下のコードを使用して、InstagramアプリにビデオURLを送信しますが、運はありません。アンドロイドのインテントを使ってinstagramアプリケーションにビデオURLを送信することはできますか?

String type = "video/*";

文字列mediaPath = "www.example.com/abcd.mp4";

Intent share = new Intent(Intent.ACTION_SEND); 

     // Set the MIME type 
     share.setType(type); 

     // Create the URI from the media 
     File media = new File(mediaPath); 
     Uri uri = Uri.fromFile(media); 

     // Add the URI to the Intent. 
     share.putExtra(Intent.EXTRA_STREAM, uri); 

     // Broadcast the Intent. 
     startActivity(Intent.createChooser(share, "Share to")); 
+0

この回答は見つかりましたか? –

+0

はい、あなたにコードを教えてください。 – shubomb

答えて

1

最後に多くの検索を行った結果、解決策が見つかりました。まず、URLからビデオをダウンロードする必要があります(ビデオがローカルストレージに保存されていない場合)。

/*ボタン*/

btn_instagram.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       if(isPackageInstalled("com.instagram.android")) { 
        createInstagramIntent(localuri); 
       }else{ 
        AlertDialog.Builder alert = new AlertDialog.Builder(ReflipActivity.this); 
        alert.setTitle("Warning"); 
        alert.setMessage("Instagram App not found"); 
        alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          dialog.dismiss(); 
         } 
        }); 
        alert.show(); 
       } 
      } 
     }); 

//チェックInstagramのアプリがデバイス上か

private boolean isPackageInstalled(String packagename) { 
     PackageManager pm = getPackageManager(); 
     try { 
      pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); 
      return true; 
     } catch (PackageManager.NameNotFoundException e) { 
      return false; 
     } 
    } 

//そして最後にInstagramの

のためのテントを発射インストールされているのInstagramに動画を共有するためにクリック
private void createInstagramIntent(String filename){ 
     String settype = "video/*"; 
     String mediaPath = filename; 

     // Create the new Intent using the 'Send' action. 
     Intent share = new Intent(Intent.ACTION_SEND); 

     // Set the MIME type 
     share.setType(settype); 
     share.setPackage("com.instagram.android"); 

     // Create the URI from the media 
     File media = new File(mediaPath); 
     Uri uri = Uri.fromFile(media); 

     // Add the URI to the Intent. 
     share.putExtra(Intent.EXTRA_STREAM, uri); 

     // Broadcast the Intent. 
     startActivity(Intent.createChooser(share, "Share to")); 
    } 
関連する問題