gpt4 book ai didi

Android Intent.ACTION_VIEW 基本身份验证

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:37:22 27 4
gpt4 key购买 nike

如何将 HTTP 基本身份验证信息传递给 Intent.ACTION_VIEW?这是我发射 Intent 的地方:

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)
}

}

我也试过 Uri.fromParts(),同样的事情。 Curl 工作得很好。

最佳答案

事实证明,您可以通过 Bundle 将 HTTP header 添加到 Intent,并专门添加一个带有 Base64 编码用户 ID 的授权 header 。

    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);

关于Android Intent.ACTION_VIEW 基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27769447/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com