我使用下面的代码将视频网址发送到Instagram应用但没有运气
String type =“video / *”;
String 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 :(得分:1)
经过大量的搜索,我终于找到了解决方案。首先,我们需要从网址下载视频(如果视频未存储在本地存储中),那么我们将应用以下代码。
/ *按钮点击以在Instagram上分享视频* /
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的Intent
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"));
}