활동 2어떻게 올바르게 안드로이드에이 의도 데이터를 전달할 수 있습니다
public class Menus extends Activity {
//set constants for MediaStore to query, and show videos
private final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
private final static String _ID = MediaStore.Video.Media._ID;
private final static String MEDIA_DATA = MediaStore.Video.Media.DATA;
//flag for which one is used for images selection
private GridView _gallery;
private Cursor _cursor;
private int _columnIndex;
private int[] _videosId;
private Uri _contentUri;
protected Context _context;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_context = getApplicationContext();
_gallery = (GridView) findViewById(R.id.videoGrdVw);
//set default as external/sdcard uri
_contentUri = MEDIA_EXTERNAL_CONTENT_URI;
//initialize the videos uri
//showToast(_contentUri.getPath());
initVideosId();
//set gallery adapter
setGalleryAdapter();
}
private void setGalleryAdapter() {
_gallery.setAdapter(new VideoGalleryAdapter(_context));
_gallery.setOnItemClickListener(_itemClickLis);
}
private AdapterView.OnItemClickListener _itemClickLis = new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
// Now we want to actually get the data location of the file
String [] proj={MEDIA_DATA};
// We request our cursor again
_cursor = managedQuery(_contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
// We want to get the column index for the data uri
int count = _cursor.getCount();
//
_cursor.moveToFirst();
//
_columnIndex = _cursor.getColumnIndex(MEDIA_DATA);
// Lets move to the selected item in the cursor
_cursor.moveToPosition(position);
Intent data = new Intent(getBaseContext(), Editor.class); data.putExtra("mnt/sdcard-ext", _ID); startActivity(data);
}
};
private void initVideosId() {
try
{
//Here we set up a string array of the thumbnail ID column we want to get back
String [] proj={_ID};
// Now we create the cursor pointing to the external thumbnail store
_cursor = managedQuery(_contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int count= _cursor.getCount();
// We now get the column index of the thumbnail id
_columnIndex = _cursor.getColumnIndex(_ID);
//initialize
_videosId = new int[count];
//move position to first element
_cursor.moveToFirst();
for(int i=0;i<count;i++)
{
int id = _cursor.getInt(_columnIndex);
//
_videosId[i]= id;
//
_cursor.moveToNext();
//
}
}catch(Exception ex)
{
}
}
//
private class VideoGalleryAdapter extends BaseAdapter
{
public VideoGalleryAdapter(Context c)
{
_context = c;
}
public int getCount()
{
return _videosId.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imgVw= new ImageView(_context);;
try
{
if(convertView!=null)
{
imgVw= (ImageView) convertView;
}
imgVw.setImageBitmap(getImage(_videosId[position]));
imgVw.setLayoutParams(new GridView.LayoutParams(96, 96));
imgVw.setPadding(8, 8, 8, 8);
}
catch(Exception ex)
{
System.out.println("StartActivity:getView()-135: ex " + ex.getClass() +", "+ ex.getMessage());
}
return imgVw;
}
// Create the thumbnail on the fly
private Bitmap getImage(int id) {
Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(
getContentResolver(),
id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
return thumb;
}
}
}
활동 3
public class Editor extends Activity {
private VideoView video;
private MediaController ctlr;
ImageButton video1;
int isClicked = 0;
ImageButton audio;
int isClicked1 = 0;
int data = getIntent(data).getExtras()
.getInt("mnt/sdcard-ext");
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.editor);
video1 = (ImageButton) findViewById(R.id.video);
video1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isClicked == 0) {
video1.setImageResource(R.drawable.video_pressed);
isClicked = 1;
} else {
video1.setImageResource(R.drawable.video1);
isClicked = 0;
}
}
});
audio = (ImageButton) findViewById(R.id.audio);
audio.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isClicked1 == 0) {
audio.setImageResource(R.drawable.audio_pressed);
isClicked1 = 1;
} else {
audio.setImageResource(R.drawable.audio);
isClicked1 = 0;
}
}
});
if (clip.exists()) {
video=(VideoView)findViewById(R.id.video);
video.setVideoPath(clip.getAbsolutePath());
ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
video.start();
}
}
}
난 그냥 통과하기 위해 노력하고있어 프로그래머가 될거야 적이 있어요 이 클래스. 그러니 걱정 마세요. 이 의도 데이터를 세 번째 활동으로 전달하는 방법을 알아야하지만 Extras를 추가하고 추가 항목을 가져올 위치가 확실하지 않습니다.
안드로이드 매니페스트
<activity
android:name=".Editor"
android:screenOrientation="landscape" >
<intent-filter>
<action
android:name="com.ave.Editor" />
<category
android:name="android.intent.category.DEFAULT" />
</intent-filter>
더 이상 필요한 경우 정보를 알려주세요. 나는이 혼란스러워하는 것을 망쳐 봤다. 그리고 어떤 도움을 주셔서 감사합니다.
가깝습니다. 그냥 그걸 시도하고 당신에게 도움이되지만 그것이 통과 해야하는 방법에 감사드립니다. 나는 그것을 더 잘 설명하려고 노력할 것이다. 활동 2는 휴대 전화의 SD 카드에서 VideoGridView의 모든 비디오 축소 이미지를 표시합니다. 어쨌든, 액티비티 2에서 미리보기 이미지를 클릭하면 3 번째 액티비티의 videoView 내에서이 뷰를 전달하고 보길 원합니다. 자동 재생은 아니지만 표시가 가능하며 화면을 클릭하면 재생할 수 있습니다. 나는 아마 그걸 알아낼 수있을 테지만, 모두 너를 도와 줄 수있어! 이것은 월요일이고 나는 스트레스를 받고있다. – Cataroux
사용자가 미리보기 이미지를 클릭하면 파일의 경로를 추가 파일로 보냅니다. 활동 3이 경로를 가져 오면 경로에서 파일을로드하고이를 VideoView에 표시해야합니다. 그런 다음 VideoView.setPath() 또는 .setURI()를 사용하여로드 한 다음 .pause()를 사용하여 자동 재생을 시도하면 일시 중지합니다. putExtra (Serializable, String) 및 getSerializableExtra (String) 메서드를 사용하여 비디오를 보낼 수 있다고 가정합니다. –
고맙습니다. 그게 효과가있을 것 같아요. – Cataroux