gpt4 book ai didi

android - 真的需要帮助 - 如何将视频附加到电子邮件?? [2个新问题]

转载 作者:行者123 更新时间:2023-11-29 02:16:38 25 4
gpt4 key购买 nike

[更新 2]:您好,

在尝试将视频附加到电子邮件后,我认为(虽然不确定!)我离目标更近了一点,但我发现了两个问题......

问题 1:文件名未正确显示:我尝试的是 toast 我点击的视频的名称,看看如何获​​得该名称。这就是我所做的...

vGrid.setOnItemClickListener(new OnItemClickListener() {

@Override // click on item and open options menu
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

String [] proj={MediaStore.Video.Media.DATA};
videocursor = managedQuery( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null,null,null);
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videocursor.moveToPosition((int) vGrid.getSelectedItemId());
// And here we get the filename
String filename = videocursor.getString(video_column_index);
Toast.makeText(ShareGalleryView.this, filename, Toast.LENGTH_SHORT).show();

openOptionsMenu(); //Opens Options Menu by clicking on an item


}
});

...但我得到的不是只显示文件名,而是 sdcard/filename.mp4,所以我的第一个问题是如何去掉“sdcard/”部分,因为如果我使用

videocursor.getString(video_column_index)

i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),videocursor.getString(video_column_index))));

为了将视频附加到邮件,我得到以下 Logcat 输出:

07-18 18:53:47.518: 错误/Mms/media(179): java.io.FileNotFoundException:/sdcard/sdcard/Video0004.mp4
那是问题 1...现在是问题 2

[问题 2] 我还发现无论我点击哪个按钮输出的文件名总是相同的并且只显示“sdcard/Video0004.mp4”,所以当我点击 Video0010它还显示“sdcard/Video0004.mp4”,因此我的第二个问题是如何确保在我的代码中显示被单击的项目并附加到电子邮件并且始终是第一个视频。

请,请帮帮我...这让我很困惑...我现在不知道如何解决这些问题。

我会在下面发布整个代码...谢谢

package com.mobilevideoeditor.moved;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;


public class ShareGalleryView extends Activity {
private Cursor videocursor;
private int video_column_index;
GridView vGrid;
int count;


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videogrid);

//create new Grid View
vGrid=(GridView) findViewById(R.id.vgrid);
registerForContextMenu(vGrid);
vGrid.setAdapter(new VideoAdapter(this));

init_phone_video_grid();

vGrid.setOnItemClickListener(new OnItemClickListener() {

@Override // click on item and open options menu
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

String [] proj={MediaStore.Video.Media.DATA};
videocursor = managedQuery( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null,null,null);
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videocursor.moveToPosition((int) vGrid.getSelectedItemId());
// And here we get the filename
String filename = videocursor.getString(video_column_index);
Toast.makeText(ShareGalleryView.this, filename, Toast.LENGTH_SHORT).show();

openOptionsMenu(); //Opens Options Menu by clicking on an item


}
});

}

private void init_phone_video_grid() {
System.gc();
String[] proj = {
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.DATA
};

videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
count = videocursor.getCount();

GridView vGrid=(GridView) findViewById(R.id.vgrid);
vGrid.setAdapter(new VideoAdapter(this));

}

@Override //creates options menu with menu-items
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_gallery_share, menu);
return super.onCreateOptionsMenu(menu);
}
@Override //what happens when a menu item is clicked
public boolean onOptionsItemSelected (MenuItem item){

try{
//Facebook
if (item.getItemId() == R.id.menu_facebook)
{
//TODO open fb
new AlertDialog.Builder(this)
.setTitle("No Service")
.setMessage("Sorry, Facebook is not supported yet!")
.setNeutralButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}}).show();
return true;

}
//YouTube
else if (item.getItemId() == R.id.menu_youtube)
{
//TODO open YouTube

new AlertDialog.Builder(this)
.setTitle("No Service")
.setMessage("Sorry, YouTube is not supported yet!")
.setNeutralButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}}).show();

return true;
}
else if (item.getItemId() == R.id.menu_email)
{

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("video/mp4");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),videocursor.getString(video_column_index))));
startActivity(i);

return true;

}
else if (item.getItemId() == R.id.menu_bluetooth)
{
// TODO send via bluetooth
new AlertDialog.Builder(this)
.setTitle("No Service")
.setMessage("Sorry, Bluetooth is not supported yet!")
.setNeutralButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}}).show();
return true;

}

}
catch(Exception e)
{
e.printStackTrace();
}
return super.onContextItemSelected(item);
}


public class VideoAdapter extends BaseAdapter {
private Context vContext;

public VideoAdapter(Context c) {
vContext = c;
}

public int getCount() {
return count;
}

public Object getItem(int position) {
return null;
}

public long getItemId(int position) {
return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
TextView tv = new TextView(vContext.getApplicationContext());
String id = null;

if (convertView == null) {
video_column_index =
videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
videocursor.moveToPosition(position);
id = videocursor.getString(video_column_index);
tv.setText(id);
} else
tv = (TextView) convertView;
return tv;
}
}

}

大家好,

我正在开发一个视频应用程序,您可以在其中单击 SD 卡中的视频。此点击事件会打开一个菜单(我使用的是选项菜单),为用户提供不同的共享选项,例如电子邮件,蓝牙等。到目前为止,这部分工作正常......我现在要做的是,当用户选择“电子邮件”时,应用程序应该通过 Intent 打开手机的电子邮件应用程序(这也可以正常工作)和应该直接将他之前点击的视频附加到新邮件中。

[UPDATE] 最后一部分是我被卡住的地方,因为我不知道如何获取单击以打开图像的图像文件名。这是我的代码中出现问题的部分(请参阅“不知道要在这里放什么”)

最佳答案

您没有跟踪点击了哪个视频 ID。

一旦你有了它,你就可以(大概)通过查询 ContentProvider 获取视频的路径(就像你在 VideoAdapter 中所做的那样)。或者,更简单 — 因为您已经在查询 MediaStore.Video.Media.DATA — 使用 convertView.setTag() 将 URL 附加到 View 。

您可以在 onItemClick 调用期间将其存储在局部变量中 — URI 应该可以通过调用 String uri = (String) v.getTag() 直接获得。

一些进一步的说明:

  • 不要调用 System.gc(),尤其不要在 getView() 方法中调用。这将导致大量不必要的减速。
  • 不要调用 vContext.getApplicationContext();只需使用 vContext
  • 您没有正确回收 View 。您的 getView 应该更像下面这样:

private static int displayNameIndex = -1;

public View getView(int position, View convertView, ViewGroup parent) {
TextView tv;

if (convertView == null) {
// Need to create a new view
tv = new TextView(context);
} else {
// Otherwise, we can recycle the one given to us
tv = (TextView) convertView;
}

// Bind cursor data to UI
videocursor.moveToPosition(position);
id = videocursor.getString(1); // column index of Media.DISPLAY_NAME
tv.setText(id);

// Bundle video URI into the view
String videoUri = videocursor.getString(2); // column index of Media.DATA
tv.setTag(videoUri);

return tv;
}

我也会看看 CursorAdapter,而不是必须自己做光标的东西(将光标移动到正确的位置等)。

关于android - 真的需要帮助 - 如何将视频附加到电子邮件?? [2个新问题],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3273855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com