Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

In this page you can find the example usage for android.content Intent setClassName.

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:Main.java

public static void send(Context context, String path) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    PackageManager pm = context.getPackageManager();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    boolean flag = false;
    for (ResolveInfo info : list) {
        if (info.activityInfo.packageName.toLowerCase().contains("bluetooth")
                || info.activityInfo.name.toLowerCase().contains("bluetooth")) {
            ApplicationInfo appInfo = null;
            try {
                appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {

            }//www . j a  v  a  2 s .c  o  m
            if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0
                    && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                flag = true;
                break;
            }
        }
    }
    if (!flag) {
        return;
    }
    context.startActivity(intent);
}

From source file:com.android.test.uibench.MainActivity.java

protected Intent activityIntent(String pkg, String componentName) {
    Intent result = new Intent();
    result.setClassName(pkg, componentName);
    return result;
}

From source file:com.googlecode.android_scripting.rpc.MethodDescriptor.java

public static Object buildIntent(JSONObject jsonObject) throws JSONException {
    Intent intent = new Intent();
    if (jsonObject.has("action")) {
        intent.setAction(jsonObject.getString("action"));
    }/*  www.  j  a  va 2 s .  c om*/
    if (jsonObject.has("data") && jsonObject.has("type")) {
        intent.setDataAndType(Uri.parse(jsonObject.optString("data", null)),
                jsonObject.optString("type", null));
    } else if (jsonObject.has("data")) {
        intent.setData(Uri.parse(jsonObject.optString("data", null)));
    } else if (jsonObject.has("type")) {
        intent.setType(jsonObject.optString("type", null));
    }
    if (jsonObject.has("packagename") && jsonObject.has("classname")) {
        intent.setClassName(jsonObject.getString("packagename"), jsonObject.getString("classname"));
    }
    if (jsonObject.has("flags")) {
        intent.setFlags(jsonObject.getInt("flags"));
    }
    if (!jsonObject.isNull("extras")) {
        AndroidFacade.putExtrasFromJsonObject(jsonObject.getJSONObject("extras"), intent);
    }
    if (!jsonObject.isNull("categories")) {
        JSONArray categories = jsonObject.getJSONArray("categories");
        for (int i = 0; i < categories.length(); i++) {
            intent.addCategory(categories.getString(i));
        }
    }
    return intent;
}

From source file:com.fastbootmobile.encore.app.fragments.SettingsProvidersFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    ProviderConnection connection = ((ProvidersAdapter) getListAdapter()).getItem(position);
    if (connection.getConfigurationActivity() != null) {
        mSettingsConnection = connection;
        Intent i = new Intent();
        i.setClassName(connection.getPackage(), connection.getConfigurationActivity());
        try {//from   ww  w  .j  av a2  s  .  c om
            startActivity(i);
        } catch (SecurityException e) {
            Log.e(TAG, "Cannot start: Is your activity not exported?", e);
            Toast.makeText(getActivity(),
                    "Cannot start: Make sure you set 'exported=true' flag on your settings activity.",
                    Toast.LENGTH_LONG).show();
        } catch (ActivityNotFoundException e) {
            Log.e(TAG, "Cannot start: Settings activity not found in the package", e);
            Toast.makeText(getActivity(),
                    "Cannot start: Make sure your activity name is correct in the manifest.", Toast.LENGTH_LONG)
                    .show();
        }
    } else {
        Utils.shortToast(getActivity(), R.string.no_settings_provider);
    }
}

From source file:com.tonikorin.cordova.plugin.LocationProvider.LocationProviderPlugin.java

private void startService(String notification) {
    Log.d(TAG, "startService");
    Context context = cordova.getActivity().getApplicationContext();
    Intent serviceIntent = new Intent();
    serviceIntent.putExtra("data", notification);
    serviceIntent.setClassName(context, "com.tonikorin.cordova.plugin.LocationProvider.LocationService");
    context.startService(serviceIntent);
}

From source file:com.sentaroh.android.BluetoothWidget.Shortcut.InvokeTetheringConfig.java

final public void onResume() {
    super.onResume();
    mLog.addDebugMsg(1, "I", "onResume entered restartStaus=" + restartStatus);

    if (WidgetUtil.isTetherAvailable(this, mLog)) {
        Intent intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
        startActivity(intent);/*  www  . j  av a 2s . c  o m*/
        finish();
    } else {
        NotifyEvent ntfy = new NotifyEvent(context);
        ntfy.setListener(new NotifyEventListener() {
            @Override
            public void positiveResponse(Context c, Object[] o) {
                finish();
            }

            @Override
            public void negativeResponse(Context c, Object[] o) {
            }
        });
        final CommonDialog commonDlg = new CommonDialog(context, getSupportFragmentManager());
        commonDlg.showCommonDialog(false, "W", "",
                getString(R.string.msgs_invoke_tether_config_tether_not_available), ntfy);
    }
    restartStatus = 1;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static void startGpMarket(Context context, String url) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    browserIntent.setClassName(PACKAGE_GP, CLASS_GP);
    browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(browserIntent);
}

From source file:ac.robinson.bettertogether.api.messaging.PluginConnectionDelegate.java

@SuppressFBWarnings("ANDROID_BROADCAST")
public void sendMessage(@NonNull BroadcastMessage message) {
    Intent intent = new Intent();
    intent.setAction(PluginIntent.ACTION_MESSAGE_RECEIVED);
    intent.setClassName(PluginIntent.HOST_PACKAGE, PluginIntent.MESSAGE_RECEIVER);
    intent.putExtra(PluginIntent.KEY_BROADCAST_MESSAGE, message);

    // note: source is only necessary for internal plugins - it may be removed at a later date
    intent.putExtra(PluginIntent.EXTRA_SOURCE, PluginMessageCallback.class.getPackage().toString());

    mContext.sendBroadcast(intent);/*  w  ww. java 2  s .  com*/
}

From source file:org.android.gcm.client.GcmIntentService.java

private Intent getPushactIntent(int flags) {
    Intent intent = new Intent();
    intent.setClassName(pushpak, pushact);
    intent.setFlags(flags | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NO_HISTORY
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}

From source file:com.firebase.jobdispatcher.ExecutionDelegator.java

@NonNull
private Intent createBindIntent(JobParameters jobParameters) {
    Intent execReq = new Intent(JobService.ACTION_EXECUTE);
    execReq.setClassName(context, jobParameters.getService());
    return execReq;
}