Example usage for android.content Intent ACTION_MEDIA_MOUNTED

List of usage examples for android.content Intent ACTION_MEDIA_MOUNTED

Introduction

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

Prototype

String ACTION_MEDIA_MOUNTED

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

Click Source Link

Document

Broadcast Action: External media is present and mounted at its mount point.

Usage

From source file:org.videolan.vlc.gui.AudioPlayerContainerActivity.java

@Override
protected void onStart() {
    super.onStart();

    //Handle external storage state
    IntentFilter storageFilter = new IntentFilter();
    storageFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    storageFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    storageFilter.addDataScheme("file");
    registerReceiver(storageReceiver, storageFilter);

    /* Prepare the progressBar */
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_SHOW_PLAYER);
    registerReceiver(messageReceiver, filter);
    mClient.connect();// w w  w .j a  v a2s . co  m
}

From source file:org.xwalk.runtime.extension.api.device_capabilities.DeviceCapabilitiesStorage.java

private void registerIntentFilter() {
    mIntentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    mIntentFilter.addDataScheme("file");
}

From source file:com.perm.DoomPlay.DownloadNotifBuilder.java

public Notification createCompleted() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setOngoing(false);/* w w w.  jav  a 2  s. c  o m*/
    builder.setContentTitle(context.getResources().getString(R.string.completed));
    builder.setContentText(track.getArtist() + "-" + track.getTitle());
    builder.setSmallIcon(R.drawable.downloaded);

    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(filePath)), "audio/*");

    builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0));
    builder.setAutoCancel(true);

    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + filePath)));

    return builder.build();
}

From source file:com.marvin.rocklock.RockLockActivity.java

/** Called when the activity is first created. */
@Override/* w  w w  .j a va  2s  .  c  o  m*/
public void onCreate(Bundle savedInstanceState) {

    mSelf = this;

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + Environment.getExternalStorageDirectory())));

    mPlayer = new RockLockMusicPlayer(this);

    super.onCreate(savedInstanceState);

    requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    setContentView(R.layout.main);
    mIconDisplay = (ImageView) findViewById(R.id.gestureIcon);
    mCurrentTrack = (TextView) findViewById(R.id.current_track);
    mCurrentInfo = (TextView) findViewById(R.id.current_info);
    mUpcomingText = (TextView) findViewById(R.id.upcoming);
    mModeText = (TextView) findViewById(R.id.mode_text);

    mGestureOverlay = (MusicGestureOverlay) findViewById(R.id.gestureLayer);
    mGestureOverlay.setGestureListener(new PlayerGestureListener(), true);
    updateDisplayText(null, null, false);

    mTts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int status) {
            mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
                @Override
                public void onUtteranceCompleted(String utteranceId) {
                    if (mCurrentUtteranceId != null && mCurrentUtteranceId.equals(utteranceId)) {
                        mPlayer.restoreMusic();
                    }
                }
            });
        }
    });
    mTts.addEarcon(TOCK_EARCON, RockLockActivity.class.getPackage().getName(), R.raw.tock_snd);
    mTts.addEarcon(TICK_EARCON, RockLockActivity.class.getPackage().getName(), R.raw.tick_snd);

    mVibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mWasStartedByService = getIntent().getBooleanExtra(EXTRA_STARTED_BY_SERVICE, false);

    mPhoneListener = new RockLockPhoneListener();
    final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    mPausedForCall = false;

    // Start the service in case it is not already running
    startService(new Intent(this, ScreenOnHandlerService.class));

    // Get notification manager
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    loadBookmarks();

    // Browsing preference
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mBrowsingPref = mPrefs.getBoolean(getString(R.string.browse_mode), true);
}

From source file:net.henryco.opalette.api.utils.Utils.java

public static File updGallery(File outputFile, Context activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        final Uri contentUri = Uri.fromFile(outputFile);
        scanIntent.setData(contentUri);/*  ww  w. j av  a2  s  . com*/
        activity.sendBroadcast(scanIntent);
    } else
        activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    return outputFile;
}

From source file:org.golang.app.WViewActivity.java

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

    //Fixed Portrait orientation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    /*this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);*/

    setContentView(R.layout.webview);//from  www .  j a  va 2  s .  c om
    WebView webView = (WebView) findViewById(R.id.webView1);

    initWebView(webView);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d("JavaGoWV: ", url);

            final Pattern p = Pattern.compile("dcoinKey&password=(.*)$");
            final Matcher m = p.matcher(url);
            if (m.find()) {
                try {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                //File root = android.os.Environment.getExternalStorageDirectory();
                                File dir = Environment
                                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                                Log.d("JavaGoWV", "dir " + dir);

                                URL keyUrl = new URL(
                                        "http://127.0.0.1:8089/ajax?controllerName=dcoinKey&first=1"); //you can write here any link
                                //URL keyUrl = new URL("http://yandex.ru/"); //you can write here any link
                                File file = new File(dir, "dcoin-key.png");

                                long startTime = System.currentTimeMillis();
                                Log.d("JavaGoWV", "download begining");
                                Log.d("JavaGoWV", "download keyUrl:" + keyUrl);

                                /* Open a connection to that URL. */
                                URLConnection ucon = keyUrl.openConnection();

                                Log.d("JavaGoWV", "0");
                                /*
                                * Define InputStreams to read from the URLConnection.
                                */
                                InputStream is = ucon.getInputStream();

                                Log.d("JavaGoWV", "01");

                                BufferedInputStream bis = new BufferedInputStream(is);

                                Log.d("JavaGoWV", "1");
                                /*
                                * Read bytes to the Buffer until there is nothing more to read(-1).
                                */
                                ByteArrayBuffer baf = new ByteArrayBuffer(5000);
                                int current = 0;
                                while ((current = bis.read()) != -1) {
                                    baf.append((byte) current);
                                }

                                Log.d("JavaGoWV", "2");
                                /* Convert the Bytes read to a String. */
                                FileOutputStream fos = new FileOutputStream(file);
                                fos.write(baf.toByteArray());
                                fos.flush();
                                fos.close();

                                Log.d("JavaGoWV", "3");
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                                    Uri contentUri = Uri.fromFile(file);
                                    mediaScanIntent.setData(contentUri);
                                    WViewActivity.this.sendBroadcast(mediaScanIntent);
                                } else {
                                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                                            Uri.parse("file://" + Environment.getExternalStorageDirectory())));
                                }

                                Log.d("JavaGoWV", "4");
                            } catch (Exception e) {
                                Log.e("JavaGoWV error 0", e.toString());
                                e.printStackTrace();
                            }
                        }
                    });
                    thread.start();

                } catch (Exception e) {
                    Log.e("JavaGoWV error", e.toString());
                    e.printStackTrace();
                }
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            Log.e("JavaGoWV", "shouldOverrideUrlLoading " + url);

            if (url.endsWith(".mp4")) {
                Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(in);
                return true;
            } else {
                return false;
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.d("JavaGoWV",
                    "failed: " + failingUrl + ", error code: " + errorCode + " [" + description + "]");
        }
    });

    SystemClock.sleep(1500);
    //if (MyService.DcoinStarted(8089)) {
    webView.loadUrl("http://localhost:8089/");
    //}

}

From source file:com.nadmm.airports.ActivityBase.java

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

    mDbManager = DatabaseManager.instance(this);
    mInflater = getLayoutInflater();/*from w w w  .  j  a  va  2s .c  o m*/
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    mHandler = new Handler();

    mFilter = new IntentFilter();
    mFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    mFilter.addAction(Intent.ACTION_MEDIA_SHARED);
    mFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    mFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
    mFilter.addDataScheme("file");

    mExternalStorageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            externalStorageStatusChanged();
        }
    };

    if (Application.sDonationDone == null) {
        DonateDatabase db = new DonateDatabase(this);
        Cursor c = db.queryAllDonations();
        Application.sDonationDone = c.moveToFirst();
        db.close();
    }

    // Enable Google Analytics
    ((Application) getApplication()).getAnalyticsTracker();
}

From source file:com.ubuntuone.android.files.fragment.AutoUploadCustomizeFragment.java

@SuppressWarnings("unused")
private void rescanWithMediaScanner() {
    final String primaryStorage = Environment.getExternalStorageDirectory().getAbsolutePath();
    final String secondaryStorage = Preferences.getSecondaryStorageDirectory().getAbsolutePath();

    Intent primaryStorageIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + primaryStorage));
    Intent secondaryStorageIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + secondaryStorage));

    Activity activity = getActivity();/*  www  . j av  a2 s. co m*/
    activity.sendBroadcast(primaryStorageIntent);
    activity.sendBroadcast(secondaryStorageIntent);
}

From source file:net.micode.fileexplorer.FileViewActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mActivity = getActivity();// w  ww.  j av  a  2s . c  om
    // getWindow().setFormat(android.graphics.PixelFormat.RGBA_8888);
    mRootView = inflater.inflate(R.layout.file_explorer_list, container, false);
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this);
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*folder only*/);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }

    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }
    mFileViewInteractionHub.setRootPath(rootDir);

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    mFileViewInteractionHub.setCurrentPath(currentDir);
    Log.i(LOG_TAG, "CurrentDir = " + currentDir);

    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    mFileViewInteractionHub.refreshFileList();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    intentFilter.addDataScheme("file");
    mActivity.registerReceiver(mReceiver, intentFilter);

    updateUI();
    setHasOptionsMenu(true);
    return mRootView;
}

From source file:com.geryon.ocraa.MusicService.java

@Override
public void onCreate() {
    // Log.i(TAG, "debug: Creating service");
    utils = new Utilities();
    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock");

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    // Create the retriever and start an asynchronous task that will prepare it.
    mRetriever = new MusicRetriever(getContentResolver());
    (new PrepareMusicRetrieverTask(mRetriever, this)).execute();

    // create the Audio Focus Helper, if the Audio Focus feature is available (SDK 8 or above)
    if (android.os.Build.VERSION.SDK_INT >= 8)
        mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this);
    else/*from   w  ww  . java 2 s .c om*/
        mAudioFocus = AudioFocus.Focused; // no focus feature, so we always "have" audio focus

    mDummyAlbumArt = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_album_art);

    mMediaButtonReceiverComponent = new ComponentName(this, MusicIntentReceiver.class);
}