搞了几个钟头,终于全兼容了,分享有2种类型!
void getDataFromIntent(Intent intent) {
if (intent.getAction().equals(Intent.ACTION_VIEW)) {
urln = intent.getDataString();
if (urln != null) {
if (urln.contains("\n"))
urln = urln.substring(urln.indexOf("\n") + 1);
newWindow(urln);
}
} else if (intent.getAction().equals(Intent.ACTION_SEND)) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
try {
urln = URLDecoder.decode(uri.toString(), "UTF-8");
} catch (Exception e) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
}
} else {
urln = intent.getStringExtra(Intent.EXTRA_TEXT);
}
if (urln != null) {
if (urln.contains("\n"))
urln = urln.substring(urln.indexOf("\n") + 1);
newWindow(urln);
}
} else if (intent.getCategories().contains(Intent.CATEGORY_LAUNCHER) && list_webView.isEmpty()) {
String surl = sharedPreferences.getString("homepage", "file:///android_asset/home.htm");
if (surl.isEmpty())
surl = "file:///android_asset/home.htm";
newWindow(surl);
}
}
@Override
protected void onNewIntent(Intent intent) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", "onNewIntent(" + getIntent() + ")");
super.onNewIntent(intent);
setIntent(intent);
getDataFromIntent(intent);
}