Wro*_*olf 4 android android-intent android-fragments
如何将HTTP基本身份验证信息传递给Intent.ACTION_VIEW?这是我表达意图的地方:
public class OutageListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
// ...
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
// Get a URI for the selected item, then start an Activity that displays the URI. Any
// Activity that filters for ACTION_VIEW and a URI can accept this. In most cases, this will
// be a browser.
String outageUrlString = "http://demo:demo@demo.opennms.org/opennms/outage/detail.htm?id=204042";
Log.i(TAG, "Opening URL: " + outageUrlString);
// Get a Uri object for the URL string
Uri outageURI = Uri.parse(outageUrlString);
Intent i = new Intent(Intent.ACTION_VIEW, outageURI);
startActivity(i)
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过Uri.fromParts(),同样的交易。卷毛效果很好。
事实证明,您可以通过捆绑包将HTTP标头添加到Intent,特别是添加带有Base64编码用户ID的Authorization标头。
Intent i = new Intent(Intent.ACTION_VIEW, outageURI);
String authorization = user + ":" + password;
String authorizationBase64 = Base64.encodeToString(authorization.getBytes(), 0);
Bundle bundle = new Bundle();
bundle.putString("Authorization", "Basic " + authorizationBase64);
i.putExtra(Browser.EXTRA_HEADERS, bundle);
Log.d(TAG, "intent:" + i.toString());
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1804 次 |
| 最近记录: |