我正在尝试添加保存功能,我想获取customTabsIntent
的当前URL。
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
PendingIntent pendingIntent;
Intent intent = new Intent();
//something
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(context,Uri.parse(URL));
答案 0 :(得分:0)
使用像这样的广播接收器:
public class CustomTabsBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = CustomTabsBroadcastReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Uri uri = intent.getData();
if (uri != null) {
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String label = "Current url";
ClipData clipData = ClipData.newUri(null, label, uri);
assert clipboardManager != null;
clipboardManager.setPrimaryClip(clipData);
}
}
}
在清单中注册接收者:
<receiver
android:name=".CustomTabsBroadcastReceiver"
android:enabled="true" />
以待定的意图获取链接,然后使用它来做您想做的事情:
Intent copyIntent = new Intent(mContext, CustomTabsBroadcastReceiver.class);
String label = "Copy link";
PendingIntent copyPendingIntent = PendingIntent.getBroadcast(mContext,
COPY_LINK_REQUEST_CODE, copyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mCustomTabsBuilder.addMenuItem(label, copyPendingIntent);