Intent.ACTION_VIEW URL of video not working on Ice Cream Sandwhich

I have the following code to view a remotely hosted video file:

startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(article.getLink())));

where getLink()returns the URL of the video associated with this article.

This approach works fine on devices prior to Gingerbread, but I recently tested the application on ICS and found a problem. The ICS browser starts loading the URL, and I see it in the navigation bar, but almost immediately the browser closes, and I return to the activity of my application.

I get the following stack trace when this happens:

11-28 10:24:44.488: E/SurfaceTexture(116): [com.mypackage.myapp/com.mypackage.myapp.MyVideoActivity] connect: already connected (cur=2, req=2)
11-28 10:24:44.488: E/ViewRootImpl(25384): IllegalArgumentException locking surface
11-28 10:24:44.488: E/ViewRootImpl(25384): java.lang.IllegalArgumentException
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.Surface.lockCanvasNative(Native Method)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.Surface.lockCanvas(Surface.java:76)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.ViewRootImpl.draw(ViewRootImpl.java:1924)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1613)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.os.Looper.loop(Looper.java:137)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.app.ActivityThread.main(ActivityThread.java:4340)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at java.lang.reflect.Method.invokeNative(Native Method)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at java.lang.reflect.Method.invoke(Method.java:511)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at dalvik.system.NativeStart.main(Native Method)

Has anyone else seen this behavior / knew about a fix?

+5
source share
2 answers

, .

Intent videoIntent =new Intent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(Uri.parse(article.getLink()), "video/*");
startActivity(videoIntent);

. Gingerbread 2.3.6.

+5

, , youtube ( ), .

/**
 * @param context
 * @param url To display, such as http://www.youtube.com/watch?v=t_c6K1AnxAU
 * @return an Intent to start the YouTube Viewer. If it is not found, will
 *         return a generic video-play intent, and system will display a
 *         chooser to ther user.
 */
public static Intent getYouTubeIntent(Context context, String url) {
  Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  final PackageManager pm = context.getPackageManager();
  List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0);
  for (int i = 0; i < activityList.size(); i++) {
    ResolveInfo app = activityList.get(i);
    if (app.activityInfo.name.contains("youtube")) {
      videoIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name);
      return videoIntent;
    }
  }
  return videoIntent;
}

@Guy → fooobar.com/questions/1094611/...

0

All Articles