Example usage for android.content Intent setComponent

List of usage examples for android.content Intent setComponent

Introduction

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

Prototype

public @NonNull Intent setComponent(@Nullable ComponentName component) 

Source Link

Document

(Usually optional) Explicitly set the component to handle the intent.

Usage

From source file:org.deviceconnect.android.manager.setting.ServiceListActivity.java

/**
 * ?????.//from  w  ww.ja v  a  2s . c  o  m
 * <p>
 * {@link #mSelectedService}??????????
 * </p>
 */
private void openPluginSettings() {
    DevicePluginManager mgr = getPluginManager();
    List<DevicePlugin> plugins = mgr.getDevicePlugins();
    for (DevicePlugin plugin : plugins) {
        if (mSelectedService.getId().contains(plugin.getPluginId())) {
            Intent request = new Intent();
            request.setComponent(plugin.getComponentName());
            request.setAction(IntentDConnectMessage.ACTION_PUT);
            SystemProfile.setApi(request, "gotapi");
            SystemProfile.setProfile(request, SystemProfile.PROFILE_NAME);
            SystemProfile.setInterface(request, SystemProfile.INTERFACE_DEVICE);
            SystemProfile.setAttribute(request, SystemProfile.ATTRIBUTE_WAKEUP);
            request.putExtra("pluginId", plugin.getPluginId());
            try {
                plugin.send(request);
            } catch (MessagingException e) {
                showMessagingErrorDialog(e);
            }
            break;
        }
    }
}

From source file:com.anjalimacwan.MainActivity.java

private void checkForAndroidWear() {
    // Notepad Plugin for Android Wear sends intent with "plugin_install_complete" extra,
    // in order to verify that the main Notepad app is installed correctly
    if (getIntent().hasExtra("plugin_install_complete")) {
        if (getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragmentAlt") == null) {
            DialogFragment wearDialog = new WearPluginDialogFragmentAlt();
            wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragmentAlt");
        }/* www  .ja  va 2  s  .com*/

        SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        editor.putBoolean("show_wear_dialog", false);
        editor.apply();
    } else {
        boolean hasAndroidWear = false;

        @SuppressWarnings("unused")
        PackageInfo pInfo;
        try {
            pInfo = getPackageManager().getPackageInfo("com.google.android.wearable.app", 0);
            hasAndroidWear = true;
        } catch (PackageManager.NameNotFoundException e) {
            /* Gracefully fail */ }

        if (hasAndroidWear) {
            try {
                pInfo = getPackageManager().getPackageInfo("com.anjalimacwan.wear", 0);
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(ComponentName
                        .unflattenFromString("com.anjalimacwan.wear/com.anjalimacwan.wear.MobileMainActivity"));
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } catch (PackageManager.NameNotFoundException e) {
                SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences",
                        Context.MODE_PRIVATE);
                if (pref.getBoolean("show_wear_dialog", true)
                        && getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragment") == null) {
                    DialogFragment wearDialog = new WearPluginDialogFragment();
                    wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragment");
                }
            } catch (ActivityNotFoundException e) {
                /* Gracefully fail */ }
        }
    }
}

From source file:com.euphor.paperpad.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    //get GCM registration id if failed to do it directly
    try {/*w w w . ja va 2s.c o m*/
        String regId = intent.getExtras().getString("registration_id");
        if (regId != null && !regId.equals("")) {
            sendRegistrationIdToBackend(context, regId);
        }

    } catch (Exception e) {
        // TODO: handle exception
    }

    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}

From source file:com.trainoft.deviceadmin.gcm.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    String message = intent.getExtras().getString("smart-intent");
    GcmUtils.printLog("smartpush intent: ", message + " id");

    // ignore if message not intended for us
    if (message == null) {
        setResultCode(Activity.RESULT_OK);
        return;//from w w w  .ja  v  a 2s  . co m
    }
    if (!message.equals("smart_tot")) {
        setResultCode(Activity.RESULT_OK);
        return;
    }

    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is
    // launching.
    startWakefulService(context, (intent.setComponent(comp)));
    //setResultCode(Activity.RESULT_OK);

    // message has been handled; do not propagate
    setResult(Activity.RESULT_OK, null, null);

}

From source file:eu.mysmartline.appv3.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    GcmBroadcastReceiver.context = context;
    //Open activity

    //Intent notificationIntent = new Intent(context, Activity3ListActivityes.class);
    /*notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);*/

    //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //Log.i(TAG, "Message receved");
    //context.startActivity(notificationIntent);

    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);/* w w  w.  j  av a2 s .  c o m*/
}

From source file:fr.bmartel.android.fadecandy.service.FadecandyService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    //this is the activity which will be opened when user click on notification
    Intent testIntent = new Intent();
    if (intent != null && intent.hasExtra(Constants.SERVICE_EXTRA_ACTIVITY)) {
        testIntent.setComponent(
                ComponentName.unflattenFromString(intent.getStringExtra(Constants.SERVICE_EXTRA_ACTIVITY)));
    }//from   ww w. j ava2 s .  c  o m

    ServiceType serviceTypeOverride;

    if (intent != null && intent.hasExtra(Constants.SERVICE_EXTRA_SERVICE_TYPE)) {
        serviceTypeOverride = ServiceType.getServiceType(intent.getIntExtra(
                Constants.SERVICE_EXTRA_SERVICE_TYPE, ServiceType.NON_PERSISTENT_SERVICE.ordinal()));
    } else {
        serviceTypeOverride = mServiceType;
    }

    switch (serviceTypeOverride) {
    case NON_PERSISTENT_SERVICE:
        Log.v(TAG, "starting NON_PERSISTENT_SERVICE...");
        return START_NOT_STICKY;
    case PERSISTENT_SERVICE:
        startForeground(4242, NotificationHelper.createNotification(this, null, testIntent));
        Log.v(TAG, "starting PERSISTENT_SERVICE...");
        return START_STICKY;
    }

    return START_NOT_STICKY;
}

From source file:org.deviceconnect.android.manager.DConnectMessageService.java

/**
 * ??./*from  w  ww. j a  v  a2 s. com*/
 * @param receiver ??BroadcastReceiver
 * @param event ??
 */
public void sendEvent(final String receiver, final Intent event) {
    if (BuildConfig.DEBUG) {
        mLogger.info(String.format("sendEvent: %s intent: %s", receiver, event.getExtras()));
    }
    Intent targetIntent = new Intent(event);
    targetIntent.setComponent(ComponentName.unflattenFromString(receiver));
    sendBroadcast(targetIntent);
}

From source file:com.microblink.blinkid.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // onActivityResult is called whenever we are returned from activity started
    // with startActivityForResult. We need to check request code to determine
    // that we have really returned from BlinkID activity.
    if (requestCode == SCAN_ACTIVITY_REQ_CODE) {

        // make sure BlinkID activity returned result
        if (resultCode == ScanActivity.RESULT_OK && data != null) {
            // set intent's component to ResultActivity and pass its contents
            // to ResultActivity. ResultActivity will show how to extract
            // data from result.
            data.setComponent(new ComponentName(this, ResultActivity.class));
            startActivity(data);// w ww  .j av a 2s. com
        } else {
            // if BlinkID activity did not return result, user has probably
            // pressed Back button and cancelled scanning
            Toast.makeText(this, "Scan cancelled!", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java

private void checkNiLSPlusLicense() {
    // if so - request a license
    Intent licenseService = new Intent();
    licenseService.setComponent(
            new ComponentName("com.roymam.android.nilsplus", "com.roymam.android.nilsplus.LicenseService"));
    mLicenseServiceConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            mService = new Messenger(service);
            try {
                // request a license from NiLSPlus app
                Message msg = Message.obtain(null, MSG_REQUEST_LICENSE);
                msg.replyTo = mMessenger;
                mService.send(msg);/*from  w  ww. j  a  v a 2  s.c o m*/
            } catch (RemoteException e) {
            }
        }

        public void onServiceDisconnected(ComponentName className) {
            mService = null;
        }
    };
    try {
        bindService(licenseService, mLicenseServiceConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception exp) {
        Log.d("NiLS", "cannot communicate with NiLS Unlocker");
        exp.printStackTrace();
    }
}

From source file:jieehd.villain.updater.VillainUpdater.java

private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;

    }/*from ww w.  ja  va2 s  .c o  m*/
    if (haveConnectedWifi == false && haveConnectedMobile == false) {
        Log.d("Network State", "false");
        AlertDialog.Builder alert = new AlertDialog.Builder(VillainUpdater.this);
        alert.setTitle("No Data Connection!");
        alert.setMessage(
                "You have no data connection, click ok to turn on WiFi or Mobile Data in order to check for OTA updates.");
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                // TODO Auto-generated method stub
                final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                final ComponentName cn = new ComponentName("com.android.settings",
                        "com.android.settings.wifi.WifiSettings");
                intent.setComponent(cn);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }

        });
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                return;
            }
        });
        alert.show();

    } else {
        download();
    }
    return haveConnectedWifi || haveConnectedMobile;
}