Skip to main content

Posts

How to read text file from sdcard in android

Program to read text file from sdcard To read a text file from sdcard, first create an object of FileInputStream class. Set the path of text file in the constructor of FileInputStream. Declare a byte array to read the file. Then call the read method. FileInputStream Fin=new FileInputStream("sdcard/"+s); byte[] b=new byte[100]; t=(TextView)findViewById(R.id.textView1); Fin.read(b); text=new String(b); t.setText(text); Fin.close(); See more Play audio from sdcard Play video from sdcard How to read image from sdcard

Program to play video in android

Play video in android, play video from sdcard  In this example,i'll show you to play video from sdcard  Create object of videoView in your activity VideoView obj=(VideoView)findViewId(R.id.videoView1); Set path of file Obj.setVideoPath(“sdcard/path of file.3gp”); Now call Obj.setMediaController(new MediaController); main.xml <? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"     android:orientation = "vertical"     android:layout_width = "fill_parent"     android:layout_height = "fill_parent"     > < TextView       android:layout_width = "fill_parent"     android:layout_height = "wrap_content"     android:text = "@string/hello"     /> < VideoView android:layout_height = "wrap_content" android:id = "@+id/videoView1" android:layout_width = "match_parent...

Play audio from sdcard programatically in android

Media Player example in android /how to play audio in android/play song from sdcard programmatically in android The Android multimedia framework includes support for playing variety of common media types, so that you can easily integrate audio, video and images into your applications. You can play audio or video from media files stored in your application's resources (raw resources), from standalone files in the filesystem, or from a data stream arriving over a network connection, all using   MediaPlayer APIs. In  this example, I’ll show you a simple program to play an audio file from sdcard. To play an audio file, first create an object of media player class MediaPlayer mp3=new MediaPlayer(); Then set path of file Mp3.setDataSource(“sdcard/filename.mp3”); Before playing audio, call prepare Mp3.prepare(); To play audio ,call Mp3.start(); To pause, call Mp3.pause To stop audio, call Mp3.stop();   main.xml <? xml version = "1.0" encoding = "utf-8" ?> ...

Screen off and on in android

Screen off and on in android/Program that listens screen off in android/listening to screen on and off in android package com.sample; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.IBinder; public class ScreenAction extends Service{       @Override       public IBinder onBind(Intent intent) {             // TODO Auto-generated method stub             return null ;       }       @Override       public void onCreate() {             // TODO Auto-generated method stub             super .onCrea...

Disable home button in Android

Override home button in android/ Disable home button in android/Stay on your activity while clicking home button in android         @Override       public   void   onAttachedToWindow(){            Log. i ( "TESTE" ,   "onAttachedToWindow" );           this .getWindow().setType(WindowManager.LayoutParams. TYPE_KEYGUARD );           super .onAttachedToWindow();        }       public   boolean   onKeyDown( int   keyCode, KeyEvent event){           if   (keyCode == KeyEvent. KEYCODE_HOME ) {               Log. i ( "TESTE" ,   "BOTAO HOME" );               return   ...