2011-07-20 4 views
0
 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 i = new Intent(); 
     i.putExtra("mnt/sdcard-ext", _ID); 
     startActivity("com.ave.EDITOR"); 


    } 
}; 

上記は私の第二の活動の一部です。基本的にこのコードは、電話機のSDカードからビデオサムネイルを表示します。とにかく、サムネイルをクリックすると、リスト内のアイテムをクリックして、下に掲載された新しいアクティビティ(ViewView)を開きます。インテントエクストラを渡すには?

public class Editor extends Activity { 

ImageButton video1; 
int isClicked = 0; 
ImageButton audio; 
int isClicked1 = 0; 
private String path = "mnt/sdcard-ext"; 
private VideoView mVideoView; 

    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    getWindow().setFormat(PixelFormat.TRANSLUCENT); 
    setContentView(R.layout.editor); 
    mVideoView = (VideoView) findViewById(R.id.videoView); 

    int data = getIntent().getExtras("mnt/sdcard-ext") .getInt("com.ave.EDITOR"); 

    if (path == "mnt/sdcard-ext") { 
     // Tell the user to provide a media file URL/path. 
     Toast.makeText(
       Editor.this, 
       "Please edit VideoViewDemo Activity, and set path" 
         + " variable to your media file URL/path", 
       Toast.LENGTH_LONG).show(); 

    } else { 

     /* 
     * Alternatively,for streaming media you can use 
     * mVideoView.setVideoURI(Uri.parse(URLstring)); 
     */ 
     mVideoView.setVideoPath(path); 
     mVideoView.setMediaController(new MediaController(this)); 
     mVideoView.requestFocus(); 



    video1 = (ImageButton) findViewById(R.id.video1); 
    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; 
      } 
      } 
     }); 
    } 
    } 
} 

あなたは私がきちんと意思エキストラを渡す方法がわからない、また私は、第三の活動からそれらを取得する方法を知っています見ることができるように。すべての助けに感謝します。ありがとうございました。

====== Androidのマニフェスト======(これは完全なマニフェストファイルではありません)

<activity android:name=".Menus" android:label="@string/app_name" android:screenOrientation="landscape" > 
     <intent-filter> 
      <action android:name="com.ave.CLEARSCREEN" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
</activity> 
<activity android:name=".Editor" android:screenOrientation="landscape" > 
     <intent-filter> 
      <action android:name="com.ave.EDITOR" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
</activity> 
</application> 
</manifest> 

答えて

0
Intent i = new Intent("com.ave.EDITOR"); 
i.putExtra("mnt/sdcard-ext", _ID); 
startActivity(i); 

及び第二の活性は:

String data = getIntent().getStringExtra("mnt/sdcard-ext"); 
+0

いいえ、「dalvik形式への変換が1つのエラーで失敗しました」という意味はありません。 – Cataroux

+0

@Catarouxあなたのプロジェクトをきれいにして再構築してみてください。 – jamapag

+0

@Cataroux私は最初のコードスニペットを編集しました。新しいものを試してみてください。 – jamapag

0

この試してみてください:あなたが意図にputExtra()を呼び出す必要がint data = getIntent().getExtras() .getInt("mnt/sdcard-ext");

+0

thatsは基本的に私はすでに持っているもの。しかし、私は動作しませんでした。 – Cataroux

+0

あなたのコードのものは、 'int data = getIntent()。getExtras(" mnt/sdcard-ext ").getInt(" com.ave.EDITOR ");です。あなたの最初の活動でもjamapagによって変更することをお勧めします(http://stackoverflow.com/questions/6767596/how-do-i-these-pass-intent-extras/6767729#6767729)。 – Mandel

0

をインスタンスをstartActivity()に渡しています。 2番目のアクティビティでは、getIntent()(アクティビティのメンバー)に電話をかけて、アクティビティを開始したインテントを取得できます。 onCreate()で行います。それから、インテントインスタンスが返されます。インテントインスタンスは、そこにパックされた余分なタイプに応じてget<type>Extra()を呼び出すことができます。あなたの要件がサポートされている基本型(Parcelableと基本的なJava型をすでに実装しているもの)を超えている場合は、独自のクラスを作成してParcelableインタフェースを実装する必要があります。

詳細についてはIntentのドキュメントをご覧ください。 onCreate方法で