Example usage for android.content ComponentName ComponentName

List of usage examples for android.content ComponentName ComponentName

Introduction

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

Prototype

private ComponentName(String pkg, Parcel in) 

Source Link

Usage

From source file:com.baidu.android.voicedemo.ApiActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sdk2_api);/*w w  w  .j av  a 2 s . com*/
    txtResult = (TextView) findViewById(R.id.txtResult);
    txtLog = (TextView) findViewById(R.id.txtLog);
    btn = (Button) findViewById(R.id.btn);
    setting = (Button) findViewById(R.id.setting);
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));

    speechRecognizer.setRecognitionListener(this);
    setting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent("com.baidu.speech.asr.demo.setting");
            startActivity(intent);
        }
    });
    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ApiActivity.this);
            boolean api = sp.getBoolean("api", false);
            if (api) {
                switch (status) {
                case STATUS_None:
                    start();
                    btn.setText("?");
                    status = STATUS_WaitingReady;
                    break;
                case STATUS_WaitingReady:
                    cancel();
                    status = STATUS_None;
                    btn.setText("");
                    break;
                case STATUS_Ready:
                    cancel();
                    status = STATUS_None;
                    btn.setText("");
                    break;
                case STATUS_Speaking:
                    stop();
                    status = STATUS_Recognition;
                    btn.setText("");
                    break;
                case STATUS_Recognition:
                    cancel();
                    status = STATUS_None;
                    btn.setText("");
                    break;
                }
            } else {
                start();
            }
        }
    });
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.IMObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.setComponent(new ComponentName(context.getPackageName(), HomeActivity.class.getName()));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);
    String msg = obj.optString(TEXT);
    (new PresenceAwareNotify(context)).notify("IM from " + from.name, "IM from " + from.name, "\"" + msg + "\"",
            contentIntent);/*from   ww  w  .ja  va  2  s.  c  o  m*/
}

From source file:de.micmun.android.workdaystarget.DaysLeftService.java

/**
 * Updates the days to target.//from w  w  w. java2s . c om
 */
private void updateDays() {
    AppWidgetManager appManager = AppWidgetManager.getInstance(this);
    ComponentName cName = new ComponentName(getApplicationContext(), DaysLeftProvider.class);
    int[] appIds = appManager.getAppWidgetIds(cName);

    DayCalculator dayCalc = new DayCalculator();
    if (!isOnline()) {
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            Log.e(TAG, "Interrupted: " + e.getLocalizedMessage());
        }
    }

    for (int appId : appIds) {
        PrefManager pm = new PrefManager(this, appId);
        Calendar target = pm.getTarget();
        boolean[] chkDays = pm.getCheckedDays();
        int days = pm.getLastDiff();

        if (isOnline()) {
            try {
                days = dayCalc.getDaysLeft(target.getTime(), chkDays);
                Map<String, Object> saveMap = new HashMap<String, Object>();
                Long diff = Long.valueOf(days);
                saveMap.put(PrefManager.KEY_DIFF, diff);
                pm.save(saveMap);
            } catch (JSONException e) {
                Log.e(TAG, "ERROR holidays: " + e.getLocalizedMessage());
            }
        } else {
            Log.e(TAG, "No internet connection!");
        }
        RemoteViews rv = new RemoteViews(this.getPackageName(), R.layout.appwidget_layout);
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
        String targetStr = df.format(target.getTime());
        rv.setTextViewText(R.id.target, targetStr);
        String dayStr = String.format(Locale.getDefault(), "%d %s", days,
                getResources().getString(R.string.unit));
        rv.setTextViewText(R.id.dayCount, dayStr);

        // put widget id into intent
        Intent configIntent = new Intent(this, ConfigActivity.class);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId);
        configIntent.setData(Uri.parse(configIntent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent pendIntent = PendingIntent.getActivity(this, 0, configIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setOnClickPendingIntent(R.id.widgetLayout, pendIntent);

        // update widget
        appManager.updateAppWidget(appId, rv);
    }
}

From source file:com.achep.acdisplay.receiver.LocalReceiverActivity.java

private void handleIntent(Intent intent) {
    String host = extractHost(intent);
    if (host == null) {
        Log.wtf(TAG, "Got an empty launch intent.");
        return;/*from   w w w  .  ja v  a  2 s  .  c  o m*/
    }

    switch (host) {
    case HOST_LAUNCH_DEVICE_ADMINS:
        Intent launchIntent = new Intent().setComponent(
                new ComponentName("com.android.settings", "com.android.settings.DeviceAdminSettings"));
        if (IntentUtils.hasActivityForThat(this, launchIntent)) {
            startActivity(launchIntent);
        } else {
            ToastUtils.showShort(this, getString(R.string.device_admin_could_not_be_started));
        }
        break;
    case HOST_UNINSTALL:
        Uri packageUri = Uri.parse("package:" + PackageUtils.getName(this));
        launchIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
        if (IntentUtils.hasActivityForThat(this, launchIntent)) {
            startActivity(launchIntent);
        } else {
            ToastUtils.showShort(this, getString(R.string.package_could_not_be_uninstalled));
        }
        break;
    default:
        Log.wtf(TAG, "Got an unknown intent: " + host);
        return;
    }

    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(host);
    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);
}

From source file:com.achep.activedisplay.receiver.LocalReceiverActivity.java

private void handleIntent(Intent intent) {
    String host = extractHost(intent);
    if (host == null) {
        Log.wtf(TAG, "Got an empty launch intent.");
        return;/*from   w  w  w. j  a v a  2 s  . c om*/
    }

    switch (host) {
    case HOST_LAUNCH_DEVICE_ADMINS:
        Intent launchIntent = new Intent().setComponent(
                new ComponentName("com.android.settings", "com.android.settings.DeviceAdminSettings"));
        if (IntentUtils.hasActivityForThat(this, launchIntent)) {
            startActivity(launchIntent);
        } else {
            ToastUtils.showShort(this, getString(R.string.device_admin_could_not_be_started));
        }
        break;
    case HOST_UNINSTALL:
        Uri packageUri = Uri.parse("package:" + Project.getPackageName(this));
        launchIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
        if (IntentUtils.hasActivityForThat(this, launchIntent)) {
            startActivity(launchIntent);
        } else {
            ToastUtils.showShort(this, getString(R.string.package_could_not_be_uninstalled));
        }
        break;
    default:
        Log.wtf(TAG, "Got an unknown intent: " + host);
        return;
    }

    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(host);
    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);
}

From source file:com.devbrackets.android.exomedia.EMLockScreen.java

/**
 * Creates a new EMLockScreen object//from www  .  j  a  v  a2  s .  c  om
 *
 * @param context The context to use for holding a MediaSession and sending action intents
 * @param mediaServiceClass The class for the service that owns the backing MediaService and to notify of playback actions
 */
public EMLockScreen(Context context, Class<? extends Service> mediaServiceClass) {
    this.context = context;
    this.mediaServiceClass = mediaServiceClass;

    ComponentName componentName = new ComponentName(context, MediaControlsReceiver.class.getName());

    mediaSession = new MediaSessionCompat(context, SESSION_TAG, componentName,
            getMediaButtonReceiverPendingIntent(componentName));
    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(new SessionCallback());
}

From source file:be.ac.ucl.lfsab1509.llncampus.ExternalAppUtility.java

/**
 * Start the Google Maps application and navigate the user to the specified location.
 * //from   w ww  . ja v a  2  s .c o  m
 * @param lat
 *          Destination latitude.
 * @param lon
 *          Destination longitude.
 * @param c
 *          Current context.
 */
public static void startNavigation(float lat, float lon, Context c) {
    try {
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                Uri.parse("http://maps.google.com/maps?daddr=" + lat + "," + lon + "&dirflg=w"));
        intent.setComponent(
                new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"));
        c.startActivity(intent);

    } catch (ActivityNotFoundException e) { // If we don't have Google Maps
        Log.e("ExternalAppUtility", c.getString(R.string.no_google_maps));
        Toast t = Toast.makeText(LLNCampus.getContext().getApplicationContext(), R.string.no_google_maps,
                Toast.LENGTH_LONG);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
    }
}

From source file:com.classiqo.nativeandroid_32bitz.ui.BaseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LogHelper.d(TAG, "Activity onCreate");

    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getTitle().toString(),
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_white),
                ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.darker_gray));
        setTaskDescription(taskDesc);/*www.  j  a  v  a2  s . c om*/
    }

    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);
}

From source file:ch.ethz.dcg.jukefox.commons.utils.AndroidUtils.java

public static String getVersionName() {
    try {//from w ww  .  j  a va 2s.co m
        Context context = JukefoxApplication.getAppContext();
        ComponentName comp = new ComponentName(context, JukefoxApplication.class);
        PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
        return pinfo.versionName;
    } catch (android.content.pm.PackageManager.NameNotFoundException e) {
        return "";
    }
}

From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.byod_nfc_test_activity);

    mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
    mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mUserMangaer = (UserManager) getSystemService(Context.USER_SERVICE);
    mDisallowByPolicy = getIntent().getBooleanExtra(EXTRA_DISALLOW_BY_POLICY, false);
    if (mDisallowByPolicy) {
        mDevicePolicyManager.addUserRestriction(mAdminReceiverComponent, UserManager.DISALLOW_OUTGOING_BEAM);
    }//from   w  w  w  .  j ava 2s . c om

    final Uri uri = createUriForImage(SAMPLE_IMAGE_FILENAME, SAMPLE_IMAGE_CONTENT);
    Uri[] uris = new Uri[] { uri };

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    mNfcAdapter.setBeamPushUris(uris, this);

    findViewById(R.id.manual_beam_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mNfcAdapter.invokeBeam(NfcTestActivity.this);
        }
    });
    findViewById(R.id.intent_share_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
            shareIntent.setType("image/jpg");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            // Specify the package name of NfcBeamActivity so that the tester don't need to
            // select the activity manually.
            shareIntent.setClassName(NFC_BEAM_PACKAGE, NFC_BEAM_ACTIVITY);
            try {
                startActivity(shareIntent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(NfcTestActivity.this, R.string.provisioning_byod_cannot_resolve_beam_activity,
                        Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Nfc beam activity not found", e);
            }
        }
    });
}