Iam試圖從模擬器中的圖庫中選擇圖片。當我點擊瀏覽日蝕在logcat中顯示W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
,但模擬器帶我到畫廊。當我選擇一張照片時,它沒有被選中。使用下面的代碼:如何從圖庫中選擇圖片?
package com.textapi;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class SendMMSActivity extends Activity {
private static final int SELECT_PICTURE = 1;
private String selectedPath, extension = "";
Uri selectedVideoUri;
Button btnBrowse;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_mms);
btnBrowse=(Button)findViewById(R.id.bnBrowse);
btnBrowse.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent,"Select Picture"),
SELECT_PICTURE);
}
});
}
public void onActivityResult(int requestCode, int resultCode,
final Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
selectedVideoUri = data.getData();
selectedPath = getPath(selectedVideoUri);
System.out.println("Path--->>"+selectedPath);
int pos = selectedPath.lastIndexOf(".");
if (pos > 0) {
extension = selectedPath.substring(pos + 1);
}
}
}
}
// We can get the path of the video using this method.
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
}
請幫我選擇圖片。而且我還需要使用MVAAYOO
api將圖片庫中的圖片發送到手機號碼。如果有人知道,請幫助我。