本文整理汇总了Java中android.net.VpnService.prepare方法的典型用法代码示例。如果您正苦于以下问题:Java VpnService.prepare方法的具体用法?Java VpnService.prepare怎么用?Java VpnService.prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.VpnService
的用法示例。
在下文中一共展示了VpnService.prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startVPNService
import android.net.VpnService; //导入方法依赖的package包/类
public void startVPNService()
{
if (!checkVPNServiceActive())
{
Intent intent = VpnService.prepare(this);
if (intent != null)
startActivityForResult(intent, 0);
else
onActivityResult(0, RESULT_OK, null);
}
}
示例2: startVPNWithProfile
import android.net.VpnService; //导入方法依赖的package包/类
private void startVPNWithProfile(VpnProfile vp) {
Intent vpnPermissionIntent = VpnService.prepare(getBaseContext());
int needPassword = vp.needUserPWInput(false);
if (vpnPermissionIntent != null || needPassword != 0) {
// VPN has not been prepared, this intent will prompt the user for
// permissions, and subsequently launch OpenVPN.
Intent shortVPNIntent = new Intent(Intent.ACTION_MAIN);
shortVPNIntent.setClass(getBaseContext(), de.blinkt.openvpn.LaunchVPN.class);
shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_KEY, vp.getUUIDString());
shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_HIDELOG, true);
shortVPNIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.cordova.getActivity().startActivity(shortVPNIntent);
} else {
Log.d(LOG_TAG, "Starting OpenVPN.");
VPNLaunchHelper.startOpenVpn(vp, getBaseContext());
}
}
示例3: startDNS
import android.net.VpnService; //导入方法依赖的package包/类
private void startDNS() {
if (presenter.isWorking()) {
presenter.stopService();
} else if (isValid()) {
Intent intent = VpnService.prepare(this);
if (intent != null) {
startActivityForResult(intent, REQUEST_CONNECT);
} else {
onActivityResult(REQUEST_CONNECT, RESULT_OK, null);
}
} else {
makeSnackbar(getString(R.string.enter_valid_dns));
}
}
示例4: onCreate
import android.net.VpnService; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mConfig = getIntent().getStringExtra(KEY_CONFIG);
mUsername = getIntent().getStringExtra(KEY_USERNAME);
mPw = getIntent().getStringExtra(KEY_PASSWORD);
Intent intent = VpnService.prepare(this);
if (intent != null) {
startActivityForResult(intent, 0);
} else {
startVpn();
finish();
}
}
示例5: onReceive
import android.net.VpnService; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (Daedalus.getPrefs().getBoolean("settings_boot", false)) {
Intent vIntent = VpnService.prepare(context);
if (vIntent != null) {
vIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(vIntent);
}
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
context.startService((new Intent(context, DaedalusVpnService.class)).setAction(DaedalusVpnService.ACTION_ACTIVATE));
Logger.info("Triggered boot receiver");
}
Daedalus.updateShortcut(context);
}
示例6: onOptionsItemSelected
import android.net.VpnService; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == R.id.action_settings)
{
startActivity(new Intent(this, SettingsActivity.class));
}
if (id == R.id.action_vpn)
{
Intent intent = VpnService.prepare(this);
if (intent != null)
{
startActivityForResult(intent, VPN_REQUEST_CODE);
}
else
{
onActivityResult(VPN_REQUEST_CODE, RESULT_OK, null);
}
}
return super.onOptionsItemSelected(item);
}
示例7: checkStartVpnOnBoot
import android.net.VpnService; //导入方法依赖的package包/类
public static void checkStartVpnOnBoot(Context context) {
Log.i("BOOT", "Checking whether to start ad buster on boot");
Configuration config = FileHelper.loadCurrentSettings(context);
if (config == null || !config.autoStart) {
return;
}
if (!context.getSharedPreferences("state", MODE_PRIVATE).getBoolean("isActive", false)) {
return;
}
if (VpnService.prepare(context) != null) {
Log.i("BOOT", "VPN preparation not confirmed by user, changing enabled to false");
}
Log.i("BOOT", "Starting ad buster from boot");
NotificationChannels.onCreate(context);
Intent intent = getStartIntent(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && config.showNotification) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}
}
示例8: startVpn
import android.net.VpnService; //导入方法依赖的package包/类
private void startVpn() {
stopwatch = new Stopwatch();
connectedServer = currentServer;
hideCurrentConnection = true;
adbBlockCheck.setEnabled(false);
Intent intent = VpnService.prepare(this);
if (intent != null) {
VpnStatus.updateStateString("USER_VPN_PERMISSION", "", R.string.state_user_vpn_permission,
VpnStatus.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT);
// Start the query
try {
startActivityForResult(intent, START_VPN_PROFILE);
} catch (ActivityNotFoundException ane) {
// Shame on you Sony! At least one user reported that
// an official Sony Xperia Arc S image triggers this exception
VpnStatus.logError(R.string.no_vpn_support_image);
}
} else {
onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null);
}
}
示例9: onClick
import android.net.VpnService; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
Intent intent = VpnService.prepare(this);
if (intent != null) {
startActivityForResult(intent, 0);
} else {
onActivityResult(0, RESULT_OK, null);
}
}
示例10: startGnirehtet
import android.net.VpnService; //导入方法依赖的package包/类
private void startGnirehtet(Context context, VpnConfiguration config) {
Intent vpnIntent = VpnService.prepare(context);
if (vpnIntent == null) {
Log.d(TAG, "VPN was already authorized");
// we got the permission, start the service now
GnirehtetService.start(context, config);
} else {
Log.w(TAG, "VPN requires the authorization from the user, requesting...");
requestAuthorization(context, vpnIntent, config);
}
}
示例11: startVPN
import android.net.VpnService; //导入方法依赖的package包/类
private void startVPN() {
waitingForVPNStart = false;
Intent vpnIntent = VpnService.prepare(this);
if (vpnIntent != null)
startActivityForResult(vpnIntent, VPN_REQUEST_CODE);
else
onActivityResult(VPN_REQUEST_CODE, RESULT_OK, null);
}
示例12: onReceive
import android.net.VpnService; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, Intent intent) {
Log.i(TAG, "Received " + intent);
Util.logExtras(TAG, intent);
// Start service
if (VpnService.prepare(context) == null)
BlackHoleService.start(context);
}
示例13: activateService
import android.net.VpnService; //导入方法依赖的package包/类
public boolean activateService() {
Intent intent = VpnService.prepare(Daedalus.getInstance());
if (intent != null) {
return false;
} else {
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
startService(Daedalus.getInstance().getServiceIntent().setAction(DaedalusVpnService.ACTION_ACTIVATE));
return true;
}
}
示例14: onClick
import android.net.VpnService; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
Intent intent = VpnService.prepare(this);
if (intent != null) {
startActivityForResult(intent, 0);
} else {
onActivityResult(0, RESULT_OK, null);
}
}
示例15: startService
import android.net.VpnService; //导入方法依赖的package包/类
private void startService() {
Log.i(TAG, "Attempting to connect");
Intent intent = VpnService.prepare(getContext());
if (intent != null) {
startActivityForResult(intent, REQUEST_START_VPN);
} else {
onActivityResult(REQUEST_START_VPN, RESULT_OK, null);
}
}