Example usage for android.content Intent ACTION_MAIN

List of usage examples for android.content Intent ACTION_MAIN

Introduction

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

Prototype

String ACTION_MAIN

To view the source code for android.content Intent ACTION_MAIN.

Click Source Link

Document

Activity Action: Start as a main entry point, does not expect to receive data.

Usage

From source file:com.mikecorrigan.bohrium.pubsub.RegistrationClient.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v(TAG, "onStartCommand: intent=" + intent + ", extras=" + Utils.bundleToString(intent.getExtras())
            + ", flags=" + flags + ", startId=" + startId);

    if (intent.getAction().equals(C2DM_INTENT_REGISTRATION)) {
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_REGISTRATION_RESPONSE, intent));
        GCMBroadcastReceiver.completeWakefulIntent(intent);
    } else if (intent.getAction().equals(C2DM_INTENT_RECEIVE)) {
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_MESSAGE, intent));
        GCMBroadcastReceiver.completeWakefulIntent(intent);
    } else if (intent.getAction().equals(C2DM_INTENT_RETRY)) {
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_RETRY_REGISTRATION, intent));
        GCMBroadcastReceiver.completeWakefulIntent(intent);
    } else if (intent.getAction().equals(Intent.ACTION_MAIN)) {
        if (mConfiguration == null) {
            mConfiguration = intent.getExtras();
        }//  w w  w .  ja  v a  2s  .co  m

        mHandler.sendEmptyMessage(EVENT_INITIALIZE);
    } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
        mHandler.sendEmptyMessage(EVENT_UNINITIALIZE);
    }

    return RegistrationClient.START_STICKY;
}

From source file:com.novemser.voicetest.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_template);

    initView();//w  ww . j  a v a 2s . c om
    //test.db?
    db = openOrCreateDatabase("alarm.db", Context.MODE_PRIVATE, null);

    mAdapter = new ListMessageAdapter(this, mDatas);
    mChatView.setAdapter(mAdapter);
    packageManager = getPackageManager();

    // Context
    BaseAction.context = getApplicationContext();

    SpeechUtility.createUtility(getApplicationContext(), SpeechConstant.APPID + "=573d5744");
    //1.RecognizerDialog
    mDialog = new RecognizerDialog(this, null);
    mIat = SpeechRecognizer.createRecognizer(getApplicationContext(), null);
    //2.accent? language?
    mDialog.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
    mDialog.setParameter(SpeechConstant.ACCENT, "mandarin");

    //?UI???onResult?
    //

    //         mDialog.setParameter("asr_sch", "1");
    //         mDialog.setParameter("nlp_version", "2.0");
    //3.?
    mDialog.setListener(new RecognizerDialogListener() {
        @Override
        public void onResult(RecognizerResult recognizerResult, boolean b) {
            Log.d("VoiceResult", recognizerResult.getResultString());
            printResult(recognizerResult);
        }

        @Override
        public void onError(SpeechError speechError) {

        }
    });

    // 4.
    mStartVoiceRecord.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //dialog
            mDialog.show();
        }
    });

    // ?TTS
    initTTS();

    // 5.??
    understander = TextUnderstander.createTextUnderstander(this, null);

    // 6.???
    SharedPreferences sharedPreferences = getSharedPreferences("user", MODE_PRIVATE);

    if (!sharedPreferences.getBoolean("isContactUploaded", false)) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        ContactManager manager = ContactManager.createManager(this, contactListener);
        manager.asyncQueryAllContactsName();
        editor.putBoolean("isContactUploaded", true);
        editor.apply();
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.title_toolbar));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        toolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    }
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    new Thread(new Runnable() {
        /**
         * ?
         */
        @Override
        public void run() {
            //?
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            resolveInfoList = packageManager.queryIntentActivities(mainIntent, 0);
            //???
            Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(packageManager));
            for (ResolveInfo res : resolveInfoList) {
                String pkg = res.activityInfo.packageName;
                String cls = res.activityInfo.name;
                String name = res.loadLabel(packageManager).toString();
                Log.d("ApplicationInfo:", "Pkg:" + pkg + "   Class:" + cls + "   Name:" + name);
            }
        }
    }).start();

    // ?
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).build();
}

From source file:io.vit.vitio.StartScreens.FragmentHolder.java

@Override
public void onBackPressed() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/*from  w  w  w . j  a v a 2 s.  co m*/
}

From source file:com.uphyca.idobata.android.service.IdobataService.java

private PendingIntent buildPendingStartActivityIntent(Message message, String organizationSlug,
        String roomName) {/* ww w  .  j a v  a  2s  .com*/

    final Intent intent = new Intent(IdobataService.this, MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setData(Uri
            .parse(String.format("https://idobata.io/#/organization/%s/room/%s", organizationSlug, roomName)));
    return PendingIntent.getActivity(IdobataService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:org.catnut.ui.HelloActivity.java

public void onMenuItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.toggle_fantasy:
        int i = mViewPager.getCurrentItem();
        if (i == 0) {
            if (mAbout.getVisibility() == View.VISIBLE) {
                mAbout.setVisibility(View.GONE);
                item.setTitle(R.string.show_fantasy_words).setIcon(R.drawable.ic_action_fullscreen_off);
            } else {
                mAbout.setVisibility(View.VISIBLE);
                item.setTitle(R.string.hide_fantasy_words).setIcon(R.drawable.ic_action_fullscreen_on);
            }/*ww  w.ja  v a2  s.  c o  m*/
        } else {
            if (mFantasyDesc.getVisibility() == View.VISIBLE) {
                mFantasyDesc.setVisibility(View.GONE);
                item.setTitle(R.string.show_fantasy_words).setIcon(R.drawable.ic_action_fullscreen_off);
            } else {
                mFantasyDesc.setVisibility(View.VISIBLE);
                item.setTitle(R.string.hide_fantasy_words).setIcon(R.drawable.ic_action_fullscreen_on);
            }
        }
        break;
    case android.R.id.home:
        Intent intent = getIntent();
        if (Intent.ACTION_MAIN.equals(intent.getAction())) {
            startActivity(new Intent(this, MainActivity.class));
        } else {
            navigateUpTo(intent);
        }
        break;
    case R.id.home:
        startActivity(new Intent(this, MainActivity.class));
        break;
    default:
        break;
    }
}

From source file:com.miz.service.TvShowsLibraryUpdate.java

private void setup() {
    if (!MizLib.isOnline(this)) {
        mStopUpdate = true;/* ww w.j a  v  a 2 s . c  om*/
        return;
    }

    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mMessageReceiver,
            new IntentFilter(STOP_TVSHOW_LIBRARY_UPDATE));

    // Set up cancel dialog intent
    Intent notificationIntent = new Intent(this, CancelLibraryUpdate.class);
    notificationIntent.putExtra("isMovie", false);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, 0);

    // Setup up notification
    mBuilder = new NotificationCompat.Builder(getApplicationContext());
    mBuilder.setColor(getResources().getColor(R.color.color_primary));
    mBuilder.setSmallIcon(R.drawable.ic_sync_white_24dp);
    mBuilder.setTicker(getString(R.string.updatingTvShows));
    mBuilder.setContentTitle(getString(R.string.updatingTvShows));
    mBuilder.setContentText(getString(R.string.gettingReady));
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setOngoing(true);
    mBuilder.setOnlyAlertOnce(true);
    mBuilder.addAction(R.drawable.ic_close_white_24dp, getString(android.R.string.cancel), contentIntent);

    // Build notification
    Notification updateNotification = mBuilder.build();

    // Show the notification
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_ID, updateNotification);

    // Tell the system that this is an ongoing notification, so it shouldn't be killed
    startForeground(NOTIFICATION_ID, updateNotification);

    mSettings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    mClearLibrary = mSettings.getBoolean(CLEAR_LIBRARY_TVSHOWS, false);
    mClearUnavailable = mSettings.getBoolean(REMOVE_UNAVAILABLE_FILES_TVSHOWS, false);
    mSyncLibraries = mSettings.getBoolean(SYNC_WITH_TRAKT, true);
}

From source file:com.saulcintero.moveon.MainHolder.java

@SuppressLint("InlinedApi")
@SuppressWarnings("deprecation")
@Override/* w w w .  ja v a2s  .  c  om*/
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.coach:
        Intent i = new Intent("android.intent.action.PRACTICE_BUTTONS_STATUS");
        if (!prefs.getBoolean("blocked", false)) {
            boolean speak = prefs.getBoolean("speak", false);
            if (speak) {
                SharedPreferences.Editor editor = prefs.edit();
                editor.putBoolean("speak", false);
                editor.commit();

                TextToSpeechUtils.setSpeak(false);
            } else {
                SharedPreferences.Editor editor = prefs.edit();
                editor.putBoolean("speak", true);
                editor.commit();

                TextToSpeechUtils.setSpeak(true);
            }
            i.putExtra("practiceButtonsStatus", "1");
            sendBroadcast(i);
        }
        break;
    case R.id.camera:
        Intent i2 = new Intent("android.intent.action.TAKE_PICTURE");
        if (!prefs.getBoolean("blocked", false) && MoveOnService.getIsPracticeRunning()) {
            sendBroadcast(i2);
        }
        break;
    case R.id.padlock:
        changeLockedStatus();

        Intent i3 = new Intent("android.intent.action.PRACTICE_BUTTONS_STATUS");
        i3.putExtra("practiceButtonsStatus", "2");
        sendBroadcast(i3);
        break;
    case R.id.music:
        if (!prefs.getBoolean("blocked", false)) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                startActivity(new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER));
            } else {
                Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_MUSIC);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        }
        break;
    case R.id.settings:
        if (!prefs.getBoolean("blocked", false))
            startActivity(new Intent(this, MoveOnPreferences.class));
        break;
    }
    return true;
}

From source file:com.amaze.filemanager.activities.Preferences.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Navigate "up" the demo structure to the launchpad activity.
        if (select == 1 && changed == 1)
            restartPC(this);
        else if (select == 1) {
            selectItem(0);/*  w  ww. j  av a 2  s .c om*/
        } else {
            Intent in = new Intent(Preferences.this, MainActivity.class);
            in.setAction(Intent.ACTION_MAIN);
            final int enter_anim = android.R.anim.fade_in;
            final int exit_anim = android.R.anim.fade_out;
            Activity activity = this;
            activity.overridePendingTransition(enter_anim, exit_anim);
            activity.finish();
            activity.overridePendingTransition(enter_anim, exit_anim);
            activity.startActivity(in);
        }
        return true;

    }
    return true;
}

From source file:com.android.tv.settings.about.AboutFragment.java

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    switch (preference.getKey()) {
    case KEY_FIRMWARE_VERSION:
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
            if (mUm.hasUserRestriction(UserManager.DISALLOW_FUN)) {
                Log.d(TAG, "Sorry, no fun for you!");
                return false;
            }/*www.  j  a va  2 s  .  c o m*/

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName("android", com.android.internal.app.PlatLogoActivity.class.getName());
            try {
                startActivity(intent);
            } catch (Exception e) {
                Log.e(TAG, "Unable to start activity " + intent.toString());
            }
        }
        break;
    case KEY_BUILD_NUMBER:
        // Don't enable developer options for secondary users.
        if (!mUm.isAdminUser())
            return true;

        if (mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES))
            return true;

        if (mDevHitCountdown > 0) {
            mDevHitCountdown--;
            if (mDevHitCountdown == 0) {
                Settings.Global.putInt(getActivity().getContentResolver(),
                        Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
                if (mDevHitToast != null) {
                    mDevHitToast.cancel();
                }
                mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on, Toast.LENGTH_LONG);
                mDevHitToast.show();
                // This is good time to index the Developer Options
                //                    Index.getInstance(
                //                            getActivity().getApplicationContext()).updateFromClassNameResource(
                //                            DevelopmentSettings.class.getName(), true, true);

            } else if (mDevHitCountdown > 0 && mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER - 2)) {
                if (mDevHitToast != null) {
                    mDevHitToast.cancel();
                }
                mDevHitToast = Toast.makeText(getActivity(), getResources().getQuantityString(
                        R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown), Toast.LENGTH_SHORT);
                mDevHitToast.show();
            }
        } else if (mDevHitCountdown < 0) {
            if (mDevHitToast != null) {
                mDevHitToast.cancel();
            }
            mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already, Toast.LENGTH_LONG);
            mDevHitToast.show();
        }
        break;
    case KEY_DEVICE_FEEDBACK:
        sendFeedback();
        break;
    case KEY_SYSTEM_UPDATE_SETTINGS:
        CarrierConfigManager configManager = (CarrierConfigManager) getActivity()
                .getSystemService(Context.CARRIER_CONFIG_SERVICE);
        PersistableBundle b = configManager.getConfig();
        if (b != null && b.getBoolean(CarrierConfigManager.KEY_CI_ACTION_ON_SYS_UPDATE_BOOL)) {
            ciActionOnSysUpdate(b);
        }
        break;
    }
    return super.onPreferenceTreeClick(preference);
}

From source file:com.smedic.tubtub.BackgroundAudioService.java

/**
 * Builds notification panel with buttons and info on it
 *
 * @param action Action to be applied//from  w w  w.jav  a2  s  . c  o  m
 */

private void buildNotification(NotificationCompat.Action action) {

    final NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();

    Intent intent = new Intent(getApplicationContext(), BackgroundAudioService.class);
    intent.setAction(ACTION_STOP);
    PendingIntent stopPendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);

    Intent clickIntent = new Intent(this, MainActivity.class);
    clickIntent.setAction(Intent.ACTION_MAIN);
    clickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent clickPendingIntent = PendingIntent.getActivity(this, 0, clickIntent, 0);

    builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setContentTitle(videoItem.getTitle());
    builder.setContentInfo(videoItem.getDuration());
    builder.setShowWhen(false);
    builder.setContentIntent(clickPendingIntent);
    builder.setDeleteIntent(stopPendingIntent);
    builder.setOngoing(false);
    builder.setSubText(videoItem.getViewCount());
    builder.setStyle(style);

    //load bitmap for largeScreen
    if (videoItem.getThumbnailURL() != null && !videoItem.getThumbnailURL().isEmpty()) {
        Picasso.with(this).load(videoItem.getThumbnailURL()).into(target);
    }

    builder.addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS));
    builder.addAction(action);
    builder.addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT));
    style.setShowActionsInCompactView(0, 1, 2);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, builder.build());

}