List of usage examples for android.content Intent ACTION_MAIN
String ACTION_MAIN
To view the source code for android.content Intent ACTION_MAIN.
Click Source Link
From source file:com.saulcintero.moveon.services.MoveOnService.java
private void showNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_silhouette).setContentTitle(getString(R.string.app_complete_name)) .setContentText(getString(R.string.local_service_started)).setOngoing(true); Intent notificationIntent = new Intent(mContext, SplashScreen.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pIntent = PendingIntent.getActivity(mContext, NOTIFICATION_ID, notificationIntent, 0); builder.setContentIntent(pIntent);//from ww w .ja v a2 s.co m Notification notif = builder.build(); mNotificationManager.notify(NOTIFICATION_ID, notif); }
From source file:com.example.lilach.alsweekathon_new.MainActivity.java
@Override public void onBackPressed() { if (mState == UART_PROFILE_CONNECTED) { Intent startMain = new Intent(Intent.ACTION_MAIN); startMain.addCategory(Intent.CATEGORY_HOME); startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(startMain);/*from w w w . j av a 2 s . c o m*/ showMessage("nRFUART's running in background.\n Disconnect to exit"); } else { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.popup_title) .setMessage(R.string.popup_message) .setPositiveButton(R.string.popup_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).setNegativeButton(R.string.popup_no, null).show(); } }
From source file:info.papdt.blacklight.ui.main.MainActivity.java
@Binded public void showMe() { openOrCloseDrawer();/*from w ww .j a v a2s.com*/ if (mUser != null) { Intent i = new Intent(); i.setAction(Intent.ACTION_MAIN); i.setClass(this, UserTimeLineActivity.class); i.putExtra("user", mUser); startActivity(i); } }
From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { Intent intent = new Intent(NowPlaying.this, SettingsActivity.class); startActivity(intent);/*from www.j av a2 s . c om*/ return true; } if (id == R.id.action_exit) { Intent broadcastIntent = new Intent(); broadcastIntent.setAction("com.smithdtyler.ACTION_EXIT"); sendBroadcast(broadcastIntent); Intent startMain = new Intent(Intent.ACTION_MAIN); startMain.addCategory(Intent.CATEGORY_HOME); startMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(startMain); finish(); return true; } if (id == android.R.id.home) { onBackPressed(); return true; } return super.onOptionsItemSelected(item); }
From source file:org.yammp.app.MusicPlaybackActivity.java
@Override public void onServiceConnected(ComponentName classname, IBinder obj) { mService = IMusicPlaybackService.Stub.asInterface(obj); try {//from w w w. j av a 2 s . co m if (mService.getAudioId() >= 0 || mService.isPlaying() || mService.getPath() != null) { updateTrackInfo(false); long next = refreshNow(); queueNextRefresh(next); setPauseButtonImage(); invalidateOptionsMenu(); mVisualizer = VisualizerWrapper.getInstance(mService.getAudioSessionId(), 50); mDisplayVisualizer = mPrefs.getBooleanState(KEY_DISPLAY_VISUALIZER, false); boolean mFftEnabled = String.valueOf(VISUALIZER_TYPE_FFT_SPECTRUM) .equals(mPrefs.getStringPref(KEY_VISUALIZER_TYPE, "1")); boolean mWaveEnabled = String.valueOf(VISUALIZER_TYPE_WAVE_FORM) .equals(mPrefs.getStringPref(KEY_VISUALIZER_TYPE, "1")); mVisualizerView.removeAllViews(); if (mFftEnabled) { mVisualizerView.addView(mVisualizerViewFftSpectrum); } if (mWaveEnabled) { mVisualizerView.addView(mVisualizerViewWaveForm); } mVisualizer.setFftEnabled(mFftEnabled); mVisualizer.setWaveFormEnabled(mWaveEnabled); mVisualizer.setOnDataChangedListener(mDataChangedListener); setVisualizerView(); } else { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClass(getApplicationContext(), MusicBrowserActivity.class); startActivity(intent); finish(); } } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.rainmakerlabs.bleepsample.BleepService.java
private void localNotification(String title, String message, Intent notificationIntent, String failMsg, int notifyId) { if (!testIntent(notificationIntent)) { //if (!BleepActivity.isTesting) // return; notificationIntent = null;/*from w w w.ja v a 2 s. co m*/ if (!failMsg.equalsIgnoreCase("")) message = failMsg; } if (notificationIntent == null) { notificationIntent = new Intent(this, BleepActivity.rootClass); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (message == null || message.equalsIgnoreCase("")) return; if (title == null || title.equalsIgnoreCase("")) title = getString(R.string.app_name); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setTicker(message).setWhen(System.currentTimeMillis()) .setAutoCancel(true).setContentTitle(title).setContentText(message).setContentIntent(contentIntent) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notifyId, builder.build()); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Deletes a application desktop shortcut icon. * * This method need two additional permissions in the application: * * <code>/*from www .ja v a 2s . com*/ * <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> * </code> * * @param context The application context. * @param appClass Shortcut's activity class. * @param appName The shortcut's name */ public static void application_shortcutRemove_method1(Context context, Class appClass, String appName) { Intent shortcutIntent = new Intent(context, appClass); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent delIntent = new Intent(); delIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); delIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName); // Inform launcher to remove shortcut delIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT"); context.sendBroadcast(delIntent); }
From source file:org.videolan.vlc.MediaService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {//from ww w. j a va 2 s . c o m Bitmap cover = AudioUtil.getCover(this, mCurrentMedia, 64); String title = mCurrentMedia.getTitle(); String artist = mCurrentMedia.getArtist(); String album = mCurrentMedia.getAlbum(); Notification notification; // add notification to status bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false) .setOngoing(true); Intent notificationIntent = new Intent(this, mIsVout ? MediaPlayerActivity.class : AudioPlayerActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Util.isJellyBeanOrLater()) { Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD); Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE); Intent iForward = new Intent(ACTION_REMOTE_FORWARD); Intent iStop = new Intent(ACTION_REMOTE_STOP); PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); if (cover != null) view.setImageViewBitmap(R.id.cover, cover); view.setTextViewText(R.id.songName, title); view.setTextViewText(R.id.artist, artist); view.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view.setOnClickPendingIntent(R.id.play_pause, piPlay); view.setOnClickPendingIntent(R.id.forward, piForward); view.setOnClickPendingIntent(R.id.stop, piStop); view.setOnClickPendingIntent(R.id.content, pendingIntent); RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded); if (cover != null) view_expanded.setImageViewBitmap(R.id.cover, cover); view_expanded.setTextViewText(R.id.songName, title); view_expanded.setTextViewText(R.id.artist, artist); view_expanded.setTextViewText(R.id.album, album); view_expanded.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view_expanded.setOnClickPendingIntent(R.id.backward, piBackward); view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay); view_expanded.setOnClickPendingIntent(R.id.forward, piForward); view_expanded.setOnClickPendingIntent(R.id.stop, piStop); view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent); notification = builder.build(); notification.contentView = view; notification.bigContentView = view_expanded; } else { builder.setLargeIcon(cover).setContentTitle(title) .setContentText(Util.isJellyBeanOrLater() ? artist : mCurrentMedia.getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startForeground(3, notification); } catch (NoSuchMethodError e) { // Compat library is wrong on 3.2 // http://code.google.com/p/android/issues/detail?id=36359 // http://code.google.com/p/android/issues/detail?id=36502 } }
From source file:com.trellmor.berrytubechat.ChatActivity.java
private void initService(BerryTubeBinder service) { mBinder = service;// www . jav a2 s . c o m if (mCallback == null) { createCallback(); } mBinder.getService().setCallback(mCallback); mBinder.getService().setChatMsgBufferSize(mScrollback); mBinder.getService().setNotification(mNotification); mNotification = null; if (mChatAdapter == null) { mChatAdapter = new ChatMessageAdapter(ChatActivity.this, R.layout.chat_item, mBinder.getService().getChatMsgBuffer()); mListChat.setAdapter(mChatAdapter); } mChatAdapter.notifyDataSetChanged(); setNick(mBinder.getService().getNick()); mDrinkCount = mBinder.getService().getDrinkCount(); updateDrinkCount(); if (!mBinder.getService().isConnected()) { try { // Only connect if we got Username and Password from // MainActivity, otherwise wait until BerryTube reconnect // normally if (mUsername != null && mPassword != null) { NotificationCompat.Builder note = new NotificationCompat.Builder(this); note.setSmallIcon(R.drawable.ic_stat_notify_berrytube); note.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); note.setContentTitle(getString(R.string.title_activity_chat)); Intent intent = new Intent(this, ChatActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.putExtra(MainActivity.KEY_USERNAME, mUsername); intent.putExtra(MainActivity.KEY_PASSWORD, mPassword); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY); note.setContentIntent( PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); mBinder.getService().connect(mUsername, mPassword, note); } } catch (MalformedURLException e) { Log.w(TAG, e); } catch (IllegalStateException e) { // already connected, ignore } } }
From source file:org.openintents.shopping.ui.ShoppingActivity.java
/** * Called when the activity is first created. *///from w ww.j av a2 s .c om @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if (debug) { Log.d(TAG, "Shopping list onCreate()"); } mSortOrder = PreferenceActivity.getShoppingListSortOrderFromPrefs(this); mDistribution.setFirst(MENU_DISTRIBUTION_START, DIALOG_DISTRIBUTION_START); // Check whether EULA has been accepted // or information about new version can be presented. if (false && mDistribution.showEulaOrNewVersion()) { return; } setContentView(R.layout.activity_shopping); // mEditItemPosition = -1; // Automatic requeries (once a second) mUpdateInterval = 2000; mUpdating = false; // General Uris: mListUri = ShoppingContract.Lists.CONTENT_URI; mItemUri = ShoppingContract.Items.CONTENT_URI; mListItemUri = ShoppingContract.Items.CONTENT_URI; int defaultShoppingList = getLastUsedListFromPrefs(); // Handle the calling intent final Intent intent = getIntent(); final String type = intent.resolveType(this); final String action = intent.getAction(); if (action == null) { // Main action mState = STATE_MAIN; mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList); intent.setData(mListUri); } else if (Intent.ACTION_MAIN.equals(action)) { // Main action mState = STATE_MAIN; mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList); intent.setData(mListUri); } else if (Intent.ACTION_VIEW.equals(action)) { mState = STATE_VIEW_LIST; setListUriFromIntent(intent.getData(), type); } else if (Intent.ACTION_INSERT.equals(action)) { mState = STATE_VIEW_LIST; setListUriFromIntent(intent.getData(), type); } else if (Intent.ACTION_PICK.equals(action)) { mState = STATE_PICK_ITEM; mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList); } else if (Intent.ACTION_GET_CONTENT.equals(action)) { mState = STATE_GET_CONTENT_ITEM; mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList); } else if (GeneralIntents.ACTION_INSERT_FROM_EXTRAS.equals(action)) { if (ShoppingListIntents.TYPE_STRING_ARRAYLIST_SHOPPING.equals(type)) { /* * Need to insert new items from a string array in the intent * extras Use main action but add an item to the options menu * for adding extra items */ getShoppingExtras(intent); mState = STATE_MAIN; mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList); intent.setData(mListUri); } else if (intent.getDataString().startsWith(ShoppingContract.Lists.CONTENT_URI.toString())) { // Somewhat quick fix to pass data from ShoppingListsActivity to // this activity. // We received a valid shopping list URI: mListUri = intent.getData(); getShoppingExtras(intent); mState = STATE_MAIN; intent.setData(mListUri); } } else { // Unknown action. Log.e(TAG, "Shopping: Unknown action, exiting"); finish(); return; } // hook up all buttons, lists, edit text: createView(); // populate the lists fillListFilter(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // Get last part of URI: int selectList; try { selectList = Integer.parseInt(mListUri.getLastPathSegment()); } catch (NumberFormatException e) { selectList = defaultShoppingList; } // select the default shopping list at the beginning: setSelectedListId(selectList); if (icicle != null) { String prevText = icicle.getString(ORIGINAL_ITEM); if (prevText != null) { mEditText.setTextKeepState(prevText); } // mTextEntryMenu = icicle.getInt(BUNDLE_TEXT_ENTRY_MENU); // mEditItemPosition = icicle.getInt(BUNDLE_CURSOR_ITEMS_POSITION); mItemUri = Uri.parse(icicle.getString(BUNDLE_ITEM_URI)); List<String> pathSegs = mItemUri.getPathSegments(); int num = pathSegs.size(); mListItemUri = Uri.withAppendedPath(mListUri, pathSegs.get(num - 1)); if (icicle.containsKey(BUNDLE_RELATION_URI)) { mRelationUri = Uri.parse(icicle.getString(BUNDLE_RELATION_URI)); } mItemsView.mMode = icicle.getInt(BUNDLE_MODE); mItemsView.mModeBeforeSearch = icicle.getInt(BUNDLE_MODE_BEFORE_SEARCH); } // set focus to the edit line: mEditText.requestFocus(); // TODO remove initFromPreferences from onCreate // we need it in resume to update after settings have changed initFromPreferences(); // now update title and fill all items onModeChanged(); mItemsView.setActionBarListener(this); mItemsView.setUndoListener(this); if ("myo".equals(BuildConfig.FLAVOR)) { try { Class myoToggleBoughtInputMethod = Class .forName("org.openintents.shopping.ui.MyoToggleBoughtInputMethod"); Constructor constructor = myoToggleBoughtInputMethod .getConstructor(new Class[] { ShoppingActivity.class, mItemsView.getClass() }); toggleBoughtInputMethod = (ToggleBoughtInputMethod) constructor .newInstance(new Object[] { this, mItemsView }); } catch (ClassNotFoundException e) { } catch (NoSuchMethodException e) { } catch (InvocationTargetException e) { } catch (InstantiationException e) { } catch (IllegalAccessException e) { } } }