使用intent打开文件管理器

时间:2014-10-26 02:48:03

标签: android android-intent android-fragments parse-platform

我希望能够打开文件管理器并选择让我们说出一首歌或图像。然后保存然后保存到Parse服务器。我认为因为我正在使用片段,所以需要从不同的方法调用intent。但应用程序崩溃了,任何帮助都会非常感激。

public class UploadFragment extends Fragment {


@Override
   public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)       { 

    View rootView = inflater.inflate (R.layout.upload_fragment, container, false);


     Button button = (Button) rootView.findViewById (R.id.uploadBtn);

      // Capture button clicks

      button.setOnClickListener (new OnClickListener () {

        public void onClick(View arg0) {

            String path="File Path";
            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_VIEW);

            intent.setData(Uri.parse (String.valueOf (path)));

            startActivity(intent);

            byte [] data = "".getBytes ();

            // Create the ParseFile
            ParseFile file  = new ParseFile ("ad.png", data);
            // Upload the image into Parse Cloud
            file.saveInBackground ();

            // Create a New Class called "ImageUpload" in Parse
            ParseObject imgupload = new ParseObject ("Ads");

            // Create a column named "ImageName" and set the string
            imgupload.put ("Ads", "AndroidBegin Logo");

            // Create a column named "ImageFile" and insert the image
            imgupload.put ("ImageFile", file);

            // Create the class and the columns
            imgupload.saveInBackground ();

            // Show a simple toast message
            Toast.makeText(getActivity(), "sent",Toast.LENGTH_LONG).show();
         }
        });
       return  rootView;
    }
}

1 个答案:

答案 0 :(得分:0)

我通过创建文件管理器类来解决它。