Issue
I've been workin on sharing video to instagram stories. In order to download file created an async task and disabled layout except for some controls while downloading. In onPostExcute() i've enabled layout and started sharing activity via intent. Though after sharing/cancelling sharing the ui is still disabled. Here is the code written inn onPostExecute().
@Override
protected void onPostExecute(String file_url) {
videoLoading.setVisibility(View.INVISIBLE);
layout.setEnabled(true);
Uri uri = Uri.parse(filePath);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
String shareBody = presenter.getVideoName();
sharingIntent.setDataAndType(uri, "vide/mp4");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
}
Solution
Have you declared your AsyncTask class properly? With the correct datatype of Params in the constructor as well as the doInBackground and onPostExecute.
And if you want only Instagram stories to handle you intent, you can do this:
Intent shareIntent = new Intent("com.instagram.share.ADD_TO_STORY");
shareIntent.setDataAndType(fileUri,"video/*");
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (shareIntent.resolveActivity(getPackageManager()) != null) {
startActivity(shareIntent);
}
Source: Sharing to Stories
(Edit)
Almost forgot: Don't call yourAsyncTaskInstance.doInBackground()
, otherwise onPostExecute()
won't run.
Instead call yourAsyncTaskInstance.execute()
. It will allow all 4 parts of AsyncTask, namely onPreExecute()
, doInBackground()
, onProgressUpdate()
and onPostExecute()
to run. Maybe disable the views inside onPreExecute
if you haven't.
Answered By - PSK1103
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.