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:com.roamprocess1.roaming4world.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    System.out.println("GcmBroadcastReceiver :onReceive ");
    Intent i = new Intent(context, SipService.class);
    context.startService(i);/*from   w w  w .  ja va  2 s. c om*/
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}

From source file:com.amazon.android.navigator.Navigator.java

/**
 * Start activity./*from   w w  w  . j a v  a2 s.c om*/
 *
 * @param currentActivity Current activity reference.
 * @param screenName      Screen name.
 * @param providedBundle  Provided bundle.
 */
private void startActivity(Activity currentActivity, String screenName, Bundle providedBundle,
        ActivitySwitchListener activitySwitchListener) {

    Class newActivityClass = mScreenNameClassMap.get(screenName);

    if (mCurrentActivity == null) {
        Log.d(TAG, "mCurrentActivity is null, switching to:" + screenName);
        Intent intent = new Intent();

        intent.setComponent(new ComponentName(mContext, newActivityClass));
        if (activitySwitchListener != null) {
            activitySwitchListener.onPreActivitySwitch(intent);
        }
        mContext.startActivity(intent);
        return;
    }

    Intent intent = new Intent(currentActivity, newActivityClass);

    if (activitySwitchListener != null) {
        activitySwitchListener.onPreActivitySwitch(intent);
    }

    Bundle bundle = providedBundle;

    IActivityTransition activityTransition = null;
    if (currentActivity instanceof IActivityTransition) {
        activityTransition = (IActivityTransition) currentActivity;

        activityTransition.onBeforeActivityTransition();
    }

    Log.d(TAG, "Activity: " + getActivityName(currentActivity) + " is starting a new " + "activity" + intent);
    if (bundle != null) {
        currentActivity.startActivity(intent, bundle);
    } else {
        currentActivity.startActivity(intent);
    }

    if (activityTransition != null) {
        activityTransition.onPostStartActivity();
    }
}

From source file:org.starfishrespect.myconsumption.android.notifications.GCMBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    try {//from  w  w  w .j  a  v  a2  s. c  o m
        // If the user don't want to receive notifications
        if (!(PrefUtils.getSyncNotification(context)))
            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);
    } catch (Exception e) {
        Log.e("GCMBroadcastReceiver: ", e.toString());
    }
}

From source file:org.alfresco.mobile.android.application.fragments.create.DocumentPropertiesDialogFragment.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(getActivity(), AnalyticsManager.SCREEN_NODE_CREATE_FORM);

    final String fragmentTag = (String) getArguments().get(ARGUMENT_FRAGMENT_TAG);
    final AlfrescoAccount currentAccount = (AlfrescoAccount) getArguments().get(ARGUMENT_ACCOUNT);
    final DocumentTypeRecord documentType = (DocumentTypeRecord) getArguments().get(ARGUMENT_DOCUMENT_TYPE);
    final ResolveInfo editor = (ResolveInfo) getArguments().get(ARGUMENT_EDITOR);

    File f = null;//from www .j ava2  s .c o m
    if (FileExplorerFragment.TAG.equals(fragmentTag)) {
        // If creation inside the download area, we store it inside
        // download.
        f = AlfrescoStorageManager.getInstance(getActivity()).getDownloadFolder(currentAccount);
    } else {
        // If creation inside a repository folder, we store temporarly
        // inside the capture.
        f = AlfrescoStorageManager.getInstance(getActivity()).getCaptureFolder(currentAccount);
    }

    final File folderStorage = f;

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.app_create_document, (ViewGroup) this.getView());

    ((TextView) v.findViewById(R.id.document_extension)).setText(documentType.extension);

    final MaterialEditText textName = ((MaterialEditText) v.findViewById(R.id.document_name));
    // This Listener is responsible to enable or not the validate button and
    // error message.
    textName.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
                textName.setFloatingLabelText(getString(R.string.content_name));
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(true);
                if (UIUtils.hasInvalidName(s.toString().trim())) {
                    textName.setError(getString(R.string.filename_error_character));
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    textName.setError(null);
                }
            } else {
                textName.setHint(R.string.create_document_name_hint);
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                textName.setError(null);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).iconRes(R.drawable.ic_application_logo)
            .title(R.string.create_document_title).customView(v, true).positiveText(R.string.create)
            .negativeText(R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onNegative(MaterialDialog dialog) {
                    dialog.dismiss();
                }

                @Override
                public void onPositive(MaterialDialog dialog) {
                    String fileName = textName.getText().toString().trim().concat(documentType.extension);

                    File newFile = new File(folderStorage, fileName);

                    if (newFile.exists() && FileExplorerFragment.TAG.equals(fragmentTag)) {
                        // If the file already exist, we prompt a warning
                        // message.
                        textName.setError(getString(R.string.create_document_filename_error));
                        return;
                    } else {
                        try {
                            // If there's a template we create the file
                            // based on
                            // this template.
                            if (documentType.templatePath != null) {
                                AssetManager assetManager = getActivity().getAssets();
                                IOUtils.copyFile(assetManager.open(documentType.templatePath), newFile);
                            } else {
                                newFile.createNewFile();
                            }
                        } catch (IOException e1) {
                            Log.e(TAG, Log.getStackTraceString(e1));
                        }
                    }

                    // We create the Intent based on informations we grab
                    // previously.
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri data = Uri.fromFile(newFile);
                    intent.setDataAndType(data, documentType.mimetype);
                    intent.setComponent(new ComponentName(editor.activityInfo.applicationInfo.packageName,
                            editor.activityInfo.name));

                    try {
                        Fragment fr = getFragmentManager().findFragmentByTag(fragmentTag);
                        if (fr != null && fr.isVisible()) {
                            if (fr instanceof DocumentFolderBrowserFragment) {
                                // During Creation on a specific folder.
                                ((DocumentFolderBrowserFragment) fr).setCreateFile(newFile);
                            } else if (fr instanceof FileExplorerFragment) {
                                // During Creation inside the download
                                // folder.
                                ((FileExplorerFragment) fr).setCreateFile(newFile);
                            }
                            fr.startActivity(intent);
                        }
                    } catch (ActivityNotFoundException e) {
                        AlfrescoNotificationManager.getInstance(getActivity())
                                .showToast(R.string.error_unable_open_file);
                    }
                    dismiss();
                }
            }).build();

    dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);

    return dialog;
}

From source file:name.setup.dance.StepService.java

/**
 * Show a notification while this service is running.
 *//*from   w  ww .j av a  2s .  c om*/
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent DanceStepAppIntent = new Intent();
    DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class));
    DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}

From source file:org.amahi.anywhere.service.AudioService.java

private void setUpAudioPlayerRemote() {
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    ComponentName audioReceiver = new ComponentName(getPackageName(), AudioReceiver.class.getName());

    Intent audioIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    audioIntent.setComponent(audioReceiver);
    PendingIntent audioPendingIntent = PendingIntent.getBroadcast(this, 0, audioIntent, 0);

    audioPlayerRemote = new RemoteControlClient(audioPendingIntent);
    audioPlayerRemote.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
            | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS);
    audioPlayerRemote.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);

    audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    audioManager.registerMediaButtonEventReceiver(audioReceiver);
    audioManager.registerRemoteControlClient(audioPlayerRemote);
}

From source file:com.inloc.dr.StepService.java

/**
 * Show a notification while this service is running.
 *//*from  w  w w. j ava2 s . c  om*/
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent pedometerIntent = new Intent();
    pedometerIntent.setComponent(new ComponentName(this, DeadReckoning.class));
    pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pedometerIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}

From source file:de.tum.in.tumcampus.services.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // If we don't have set up our chat don't work with any GCM Notifications
    if (Utils.getPrivateKeyFromSharedPrefs(context) == null) {
        return;// ww w.  ja  v  a  2s  .  com
    }

    // 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:org.ewicom.pps.unitinfo.TabAddressFragment.java

public void openUnitOnMap() {
    String latitude = unit.getLatitude();
    String longitude = unit.getLongitude();

    Context context = getActivity().getApplicationContext();
    Toast noGeotoast = Toast.makeText(context, R.string.empty_geodata, Toast.LENGTH_SHORT);
    Toast noAppMap = Toast.makeText(context, R.string.no_map_app, Toast.LENGTH_LONG);

    if (StringUtils.isEmpty(latitude)) {
        noGeotoast.show();/*  www . j  ava 2s.  c  om*/
    } else {
        String geoUri = "geo:" + latitude + "," + longitude + "?q=" + latitude + "," + longitude;
        Intent showUnitOnMapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
        showUnitOnMapIntent.setComponent(
                new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"));

        if (PPSAddressBook.isIntentAvailable(getActivity(), showUnitOnMapIntent)) {
            startActivity(showUnitOnMapIntent);
        } else {
            noAppMap.show();
        }

    }
}

From source file:com.smsdroid.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    //if(p.isactiver())
    if (pref.getBoolean("smsdroid_setting_activate", false)) {
        // 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  w ww  . jav a2  s. com*/
}