我认为基本上错误在Manifest文件中。
以下是MainActivity.java的代码
private void setInitialScreen( int visibility ) {
Button choose_picture = (Button) findViewById(R.id.choose_picture);
choose_picture.setVisibility(visibility);
choose_picture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.addCategory("choose_file");
Log.d("mainactivity", intent.getCategories().toString());
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(data.hasCategory("choose_file") && resultCode == RESULT_OK) {
Uri uri = data.getData();
setPhotoEditScreen(0, uri);
}
}
private void setPhotoEditScreen( int visibility, Uri uri ) {
View screen_image_editing = findViewById(R.id.screen_image_editing);
screen_image_editing.setVisibility(visibility);
ImageView main_image = (ImageView) findViewById(R.id.main_image);
main_image.setImageURI(uri);
}
这是清单条目
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="choose_file"/>
</intent-filter>
</activity>
Logcat的屏幕截图
https://www.dropbox.com/s/w0hi3g7n3i966t6/Screenshot%202014-04-14%2010.33.17.jpg
答案 0 :(得分:1)
<intent-filter >
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="choose_file"/>
</intent-filter>
请从manifest.xml中删除以下行并尝试一下,我认为因为它有两个intent过滤器可能存在问题并且在android名称中并且您已将包名称包含在
中 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.splash_1"
喜欢这个