2
I’m having problems when I try to run a video, which I choose in my gallery, in my app (simple).
Follow what I’ve done so far. If anyone can help me..
Mainactivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
play = (Button) findViewById(R.id.play);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent GaleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(GaleryIntent, RESULT_LOAD_IMAGE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri SelectedImage = data.getData();
Intent intent = new Intent(this, Video.class);
intent.putExtra("imagemUri", SelectedImage);
startActivity(intent);
}
}
Videoactivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
video = (VideoView) findViewById(R.id.video_frame);
Intent intent = getIntent();
Uri uri = intent.getParcelableExtra("imagemUri");
video.setVideoURI(uri);
video.start();
}
My XML is a button on the main, and a VideoView
in VideoActivity
.
log
10-19 22:04:51.347: E/AndroidRuntime(926): FATAL EXCEPTION: main
10-19 22:04:51.347: E/AndroidRuntime(926): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.PICK dat=content://media/external/video/media cmp=com.android.music/.VideoBrowserActivity } from ProcessRecord{407b58d0 926:com.example.bancoimagem/10034} (pid=926, uid=10034) requires null
10-19 22:04:51.347: E/AndroidRuntime(926): at android.os.Parcel.readException(Parcel.java:1322)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.os.Parcel.readException(Parcel.java:1276)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1351)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.app.Activity.startActivityForResult(Activity.java:2827)
10-19 22:04:51.347: E/AndroidRuntime(926): at com.example.bancoimagem.MainActivity$1.onClick(MainActivity.java:35)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.view.View.performClick(View.java:2485)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.view.View$PerformClick.run(View.java:9080)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.os.Handler.handleCallback(Handler.java:587)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.os.Handler.dispatchMessage(Handler.java:92)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.os.Looper.loop(Looper.java:123)
10-19 22:04:51.347: E/AndroidRuntime(926): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-19 22:04:51.347: E/AndroidRuntime(926): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 22:04:51.347: E/AndroidRuntime(926): at java.lang.reflect.Method.invoke(Method.java:507)
10-19 22:04:51.347: E/AndroidRuntime(926): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-19 22:04:51.347: E/AndroidRuntime(926): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-19 22:04:51.347: E/AndroidRuntime(926): at dalvik.system.NativeStart.main(Native Method)
You say, "I’m having problems when..."?
– ramaral
@ramaral I click the button, open my video gallery, when selecting a video the application hangs and closes "Unfortunately, 'App name' stopped"
– Junior Barreto
In that case post the log of errors.
– ramaral
@ramaral I edited and put the log. Strange that in the emulator the application of the problem when I click the button. Already on my mobile the application fails when I select the video I want to play...
– Junior Barreto
Does not lack a permission of
READ_EXTERNAL_STORAGE
?– Wakim
@Wakim also thought it might be, but I checked and got this permission in the manifest
– Junior Barreto