我的活动流程为A - > B - > C。在活动C中有共享选项。分享后想要在活动C中保留位置但是它将转到活动A。
分享意图代码
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"));
这是我的活动C代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
CommonUtils.setCommonVariables(this, this);
findViewById(R.id.buttonBackDisplay).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
// //TODO TEMP MP added to check engine in debug mode on chrome
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// WebView.setWebContentsDebuggingEnabled(true);
// }
aviaryUtils = new AviaryUtils(this);
myCompanyJSONObject = CommonUtils.loadCompanyJsonFile(this, CommonUtils.E_COMPANY_JSON_FILE);//Reading Company json
if (myCompanyJSONObject != null) //if CompanyjsonObject is null then create new one
{
mySaveFormat = CommonUtils.getStringFromJson(myCompanyJSONObject, CommonUtils.E_COMPANY_SAVE_FORMAT, "");
}
myRelativeLayoutAviaryDesign=(RelativeLayout)findViewById(R.id.relativeLayoutAviaryDesign);
myImageViewAviaryDesign=(ImageView)findViewById(R.id.imageViewAviaryDesign);
myWebviewDisplay = (WebView) findViewById(R.id.webviewDisplay);
myWebviewDisplay.clearCache(true);
myWebviewDisplay.clearHistory();
myWebviewDisplay.clearFormData();
WebSettings webSettings = myWebviewDisplay.getSettings();
// To enable java script on page.
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDomStorageEnabled(true);
//webSettings.setAllowFileAccessFromFileURLs(true);
//webSettings.setAllowUniversalAccessFromFileURLs(true);
//To always load page from web server, not to use resources from cache.
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
int currentapiVersion = Build.VERSION.SDK_INT;
if (currentapiVersion >= Build.VERSION_CODES.JELLY_BEAN) {
fixNewAndroid(myWebviewDisplay);
}
Log.d("MP111", "MP111");
myWebviewDisplay.setWebChromeClient(new WebChromeClient() {
// TODO
});
myWebviewDisplay.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.d("onPageStarted()", url);
if (url.contains("abhigna.info")) {
//view.stopLoading();
//Log.d("view.stopLoading()","stopped url:"+ url);
////return;
}
super.onPageStarted(view, url, favicon);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
if (url.indexOf("file:///android_asset") == 0 && url.contains("?")) {
String filePath = url.substring(22, url.length());
filePath = filePath.substring(0, filePath.indexOf("?"));
try {
InputStream is = DisplayActivity.this.getAssets().open(filePath);
WebResourceResponse wr = new WebResourceResponse("text/html", "Cp1252", is);
return wr;
} catch (IOException e) {
return null;
}
} else {
return null;
}
} else
return super.shouldInterceptRequest(view, url);
}
myWebviewDisplay.loadUrl(tempString);
return true;
}
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(DisplayActivity.this, "6001 - Error! " + description, Toast.LENGTH_SHORT).show();
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
Log.d("MP222", "MP222");
//root_sd = Environment.getExternalStorageDirectory().toString();
myDataJsonPath = CommonUtils.SDCardBasePath + "/" + CommonUtils.DATA_FOLDER_NAME + "/" +
CommonUtils.E_DATA_JSON_FILENAME;
Log.d("Oncreate.SDCardBasePath", CommonUtils.SDCardBasePath);
Log.d("MPOncreate_dataJsonPath", myDataJsonPath);
//Toast.makeText(this, dataJsonPath, Toast.LENGTH_LONG).show();
//String dataJsonPath="file://"+root_sd+"/"+ICardXpressCommonUtils.APP_FOLDER_NAME+"/Data/data.json";
//String dataJsonPath="data1.json";
Log.d("MP333", "MP333");
File f = new File(myDataJsonPath);
if (f.exists()) {
System.out.println("Exist......");
}
byte[] bytes = myDataJsonPath.getBytes();
String hexValue = "";
for (int i = 0; i < bytes.length; i++) {
hexValue = hexValue + byteToHex(bytes[i]);
System.out.println("bytes[" + i + "] " +
(i <= 9 ? " = " : " = ") +
((int) bytes[i] < 9 ? " " : "") +
(((int) bytes[i] > 9 && (int) bytes[i] <= 99) ? " " : "") +
bytes[i] + " : " +
" HEX=(0x" + byteToHex(bytes[i]) + ") : " +
" charValue=(" + (char) bytes[i] + ")");
}
System.out.println("hexValue:" + hexValue);
Date convertedDate = new Date();
String format = "yyMMddhhmmss";
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
myStrUrl = getResources().getString(R.string.bundle_path) + "/" +
CommonUtils.BMX_DEMO_FOLDER_NAME + "/index.html?" + CommonUtils.APP_QUERYSTRING + "=" +
CommonUtils.APP_NAME + "&" + CommonUtils.CALL_TYPE_QUERYSTRING + "=" +
CommonUtils.CALL_TYPE_EXECUTION + "&" + CommonUtils.DATA_JSON_PATH_QUERYSTRING + "=" + hexValue +
"&t=" + sdf.format(convertedDate).toString() + "&save=" + mySaveFormat;
Log.v("MPOnCreatestrUrl1", myStrUrl);
final DisplayBrandMobileActivityWebAppInterface dgJavaScriptInterface = new DisplayBrandMobileActivityWebAppInterface(this);
myWebInterfaceName = String.format("Dg%sWeb", "BrandMobile");
myWebviewDisplay.addJavascriptInterface(dgJavaScriptInterface, myWebInterfaceName);
myWebviewDisplay.loadUrl(myStrUrl);
}
点击片段分享按钮后,它将调用共享意图。
答案 0 :(得分:0)
您可以通过启动结果活动
来等待Share Activity
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"), REQUEST_ID); // declare global REQUEST_ID = 999 or whatever
然后您将在onActivityResult
接听电话,在分享后做任何您想做的事情。
希望这会有所帮助。