You can open other app or intent from own application, After finish some actions in the other app, back to original application.
Last active
January 11, 2017 06:23
-
-
Save pokk/94d68c40a3886034274e2cf14b06c2fd to your computer and use it in GitHub Desktop.
Create a intent to open other intent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
public static final int INPUT_FILE_REQUEST_CODE = 5568; | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (RESULT_OK == resultCode) { | |
switch (requestCode) { | |
case INPUT_FILE_REQUEST_CODE: | |
Uri[] results = new Uri[] { }; | |
// If there is not data, then we may have taken a photo | |
if (null != data) { | |
// From camera picture. | |
if (null != data.getExtras()) { | |
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "image.jpg"); | |
if (file.exists()) { | |
file.delete(); | |
file = new File(Environment.getExternalStorageDirectory() + File.separator + "image.jpg"); | |
} | |
try { | |
OutputStream outStream = new FileOutputStream(file); | |
Bitmap photo = (Bitmap) data.getExtras().get("data"); | |
// make a new bitmap from your file | |
if (null != photo) { | |
photo.compress(Bitmap.CompressFormat.PNG, 100, outStream); | |
} | |
outStream.flush(); | |
outStream.close(); | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
results = new Uri[] {Uri.fromFile(file)}; | |
} | |
// Photo selection or video. | |
else { | |
if (null != data.getClipData()) { | |
results = new Uri[data.getClipData().getItemCount()]; | |
for (int i = 0 ; i < data.getClipData().getItemCount() ; i++) { | |
results[i] = data.getClipData().getItemAt(i).getUri(); | |
} | |
} | |
if (null != data.getDataString()) { | |
results = new Uri[] {Uri.parse(data.getDataString())}; | |
} | |
} | |
if (null != mFilePathCallback) { | |
mFilePathCallback.onReceiveValue(results); | |
mFilePathCallback = null; | |
} | |
} | |
break; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ValueCallback<Uri[]> mFilePathCallback; | |
public class MyWebChromeClient extends WebChromeClient { | |
@Override | |
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { | |
AppLog.v(); | |
if (mFilePathCallback != null) { | |
mFilePathCallback.onReceiveValue(new Uri[] { }); | |
mFilePathCallback = null; | |
} | |
mFilePathCallback = filePathCallback; | |
// Create camera intent for taking a picture. | |
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
// Create camera video intent for recording a video. | |
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); | |
// Create intent for picking a photo from the gallery | |
Intent photosSelectionIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
// Create intent for picking any data type of file. | |
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); | |
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); | |
contentSelectionIntent.setType("*/*"); | |
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); | |
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action"); | |
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, | |
new Intent[] {takePictureIntent, videoIntent, photosSelectionIntent}); | |
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); | |
this.activity.startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment