- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
[更新 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
。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/
所以我的问题是我希望我的文本显示在页面的死 Angular 。我一直在尝试手动对齐它,但这似乎是一种糟糕的做法。我想要它,这样即使网页被调整为更小或者用户使用的是更小的屏幕,无序列表也会显示在屏幕的死
所以基本上,我有这段代码,它选择一个下拉菜单选项,然后按下它。我需要它按第一个选项,然后按第二个选项。 var x = document.getElementById("product-select"
我编写了我的第一个 C 程序。它去除 C 注释 ('//')。我将一个字符串传递给函数 strip_comments,创建一个与参数字符串大小相同的新字符串,然后我逐个复制一个字符,忽略注释。 这是代
我在运行下面代码中提到的清理名称实用程序时收到运行时错误 7 错误。我使用的是 512 GB 硬盘、8 GB RAM、I7 处理器,所以不应该是内存问题,但问题仍然会出现。 我的工作簿有 123188
我知道很多人都会问有关插件和回调的问题(我已经阅读了很多内容 - 这就是我到目前为止的方式),所以请耐心等待。我尝试了一个非常简单的隐藏/显示 Accordion 类型插件来解决常见问题,并成功地让它
请原谅我,如果之前已经介绍过,我搜索无济于事。 我有一个脚本可以查看目录以找到其中的文件。有一个条件行只查找具有特定扩展名的文件: if(strtolower(substr($file, -3)) =
使用链接列表扩展哈希表时会出现一些错误和警告。我想确保以下代码是正确的(扩展函数)并找出引发这些警告/错误的原因 编辑:感谢@nos,他注意到我的原型(prototype)缺少我提到的警告+错误。不幸
我已经搜索了网络,并且共识似乎是将$ {SDK_DIR}/usr/lib/libxml2添加到“Header Search Paths”中。我已经完成了此操作,并且可以在项目检查器中看到它扩展了,以更
很抱歉新手。 我想在 LinearLayout(垂直)中创建一个 View 元素列表。我创建了一个名为“category_list.xml”的 TableLayout 的 xml 布局
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
全新的 Xcode 版本,除了删除大量添加空函数调用的地方外,还引入了一个有趣的问题,用一段简单的代码绘制了一条大地路径: func drawPolyline(from startLocation:
我之前的问题可以在这里找到(只是想向这个最有帮助的社区保证我不会试图垃圾邮件问题): Evaluating a postfix Expression in C 我的问题涉及评估后缀表达式。假设我有一个
嘿嘿 我的声纳kotlin插件已启动并正在运行。我的RuleDefinitions放置在“规则”页面上,但是在分析某些Kotlin项目时,不会保存发现的问题。 我的传感器问题添加代码如下所示: pri
这是我在这里发表的第一篇文章。我是初学者。我正在开发一个 Spring Boot 应用程序。尝试了很多解决方案后,问题都没有得到解决。请帮忙(如果缺少任何代码片段,我会发送它。): 控制台: Erro
我是一名优秀的程序员,十分优秀!