How to open file with any exetension in Android?

前端 未结 3 778
走了就别回头了
走了就别回头了 2021-01-12 09:22

I have an app in which user can upload file with any exetention(.png,.mp3,.txt,.pdf

3条回答
  •  情深已故
    2021-01-12 09:47

    Pointing to the first part of your question:

    try
    {
      Intent intent = new Intent(Intent.ACTION_VIEW, uri);
      startActivity(intent);
    }
    catch (ActivityNotFoundException e)
    {
      //tel the user to install viewer to perform this action
    }
    

    There's no need to specify the type. It will get it from the data URI.

提交回复
热议问题