Android open another application from EditText - android

Can we open other app through this code by executing command given through the Edittext view. If yes then how it can be done?
package com.example.honey.shell;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class MainActivity extends AppCompatActivity {
TextView op;
EditText ip;
Button exec;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
op = (TextView) findViewById(R.id.textView);
ip = (EditText) findViewById(R.id.editText);
exec = (Button) findViewById(R.id.button);
}
public void execute(View view) {
String input = ip.getText().toString();
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(input);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
} catch (Exception e) {}
op.setText(output.toString());
}
}
Actually i wish to open some other application from my app by executing the command but it's not working,as I tried commands such as cd but it didn't work only the ls command is working in it...

to open an application from another app , you can use Intents
Intent launchNewApp = getPackageManager().getLaunchIntentForPackage("com.example.name");//specify the package name of other application which you intended to launch
if (launchNewApp != null) {
startActivity(launchIntent);//null pointer check in case package name was not found
}

Related

Problem with dynamically updating text view

I have implemented the logs and they are being displayed on the screen. But even after creating the thread, the logs are not being dynamically updated on the screen. New logs should be appended after one second. While the user stays on the screen, the logs should keep displaying on the screen but it is not happening. The thread that I have created works fine as I have tested it with a count variable. But with logs, it does not seem to work.
Help me out, I am stuck here.
package com.example.logreader;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;
public class MainActivity extends Activity {
private int mInterval = 100; // 5 seconds by default, can be changed later
private Handler mHandler;
int count;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView)findViewById(R.id.textView);
Thread t=new Thread(){
#Override
public void run(){
while(!isInterrupted()){
try {
Thread.sleep(1000); //1000ms = 1 sec
runOnUiThread(new Runnable() {
#Override
public void run() {
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log=new StringBuilder();
String line = "";
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
}
tv.setText(log.toString());
tv.setMovementMethod(new ScrollingMovementMethod());
} catch (IOException e) {
}
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.start();
}
}
Use LiveData and observables it is very powerful and your life becomes easy

File not found Exception in Android but File Exists

I am trying to get the address of any file on android and then read its content.
I am getting the location of file as :
uri2.toString() gives string "file:///storage/emulated/0/download/user.txt"
uri2.getEndodedPath() gives string "/storage/emulated/0/download/user.txt"
when passing these value to file it gives file not found exception
Note : I am not reading file from sdcard or asset folder or raw folder and i am testing my app on mobile one plus cyanogen mod
here is my android code
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.nfc.Tag;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Locale;
public class MainSpeechActivity extends Activity {
TextToSpeech tts;
Button btn;
private String uri;
private Uri uri2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_speech);
final Intent intent = getIntent();
final String action = intent.getAction();
if(Intent.ACTION_VIEW.equals(action)){
//uri = intent.getStringExtra("URI");
uri2 = intent.getData();
uri = uri2.getEncodedPath() + " complete: " + uri2.toString();
TextView textView = (TextView)findViewById(R.id.textView);
TextView textView2 = (TextView)findViewById(R.id.textView2);
textView.setText(uri);
// now you call whatever function your app uses
String str = uri2.toString();// value is mentioned above
File f = new File(str);
BufferedReader br = null;
String line;
StringBuilder sbr = new StringBuilder();
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
while((line = br.readLine()) != null) {
sbr.append(line);
sbr.append("\n");
}
br.close();
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(),"FileNotFound",Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"InputError",Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
if(sbr.toString().isEmpty())
textView2.setText("Blah blah");
else
textView2.setText(sbr.toString());
} else {
Log.d("know", "intent was something else: " + action);
}
tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int i) {
if( i != TextToSpeech.ERROR) {
tts.setLanguage(Locale.ENGLISH);
}
}
});
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String toSpeak = "My friend is very good programmer do you aggree";
Toast.makeText(getApplicationContext(),toSpeak,Toast.LENGTH_SHORT).show();
tts.speak(toSpeak,TextToSpeech.QUEUE_FLUSH,null);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_speech, menu);
return true;
}
#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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
If reading file from android is not possible then how to copy that file to sdcard or at location where reading and writing is possible
I am trying to get the address of any file on android and then read its content.
I am not reading file from sdcard
Then your options are fairly limited. The only way you can read a file from internal storage is if your app is allowed to access that part of internal storage.
However, seeing that you're trying to read from downloads, it should be fine. I think the problem is your file path is badly formatted:
file:///storage/emulated/0/download/user.txt
Should just be
/storage/emulated/0/download/user.txt
which you have the value of, you just need to set your str variable to getEncodedPath instead of toString

Run script with android app

i've got this shell script:
#!system/bin/sh
while :
do
sync
echo 3> /proc/sys/vm/drop_caches
echo "Script is been launched"
sleep 30m
done
exit 0;
i wish run this script with an android app. I have already created a button with only a toast for now. How can i take the script (free.sh) and launch it with the button on the app? Or is there a solution to rewrite the code in java? Thanks
First, you will use Eclipse to create a simple Android helloworld app.
And add a button in your layout. This is very priliminary practise of Android development which you can dig a lot more from http://d.android.com
please try this code in your button's onclick call back function:
Button b = (Button)findViewById(R.id.buttonPower);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Process p=null;
try {
p = new ProcessBuilder()
.command("PathToYourScript")
.start();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(p!=null) p.destroy();
}
}
});
Here is how you can run shell script from your android app
try {
Process process = Runtime.getRuntime().exec("sh /sdcard/test.sh");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String listOfFiles = "";
String line;
while ((line = in.readLine()) != null) {
listOfFiles += line;
}
}
catch (IOException e) {
e.printStackTrace();
}
Well, now No errors (THANK YOU!) but do nothing..to try i've written a easy script that write a file.txt. See the code:
package com.mkyong.android;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import com.example.toast.R;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#SuppressLint("SdCardPath")
#Override
public void onClick(View arg0) {
Process p=null;
try {
p = new ProcessBuilder()
.command("/sdcard/Script/scritturafile.sh")
.start();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(p!=null) p.destroy();
}
}
});
}
}
The are no errors but when i press the button i think the shell doesn't go so don't create the file.txt
I've got errors in my code:
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.example.toast.R;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Process process = new ProcessBuilder()
.command("PATH")
.redirectErrorStream(true)
.start();
try {
InputStream in = process.getInputStream();
OutputStream out = process.getOutputStream();
readStream(in);// Here: Syntax error, insert "}" to complete `Block`
finally {
process.destroy();
}
}
}
}); //Here: Syntax error on token "}", delete this token
}
protected void readStream(InputStream in) {
// TODO Auto-generated method stub
}
}

How to get wifi hardware information on Android

Following will give me basic wifi information, but I want the hardware information:
WiFiScanReceiver.java
import java.util.List;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.widget.Toast;
public class WiFiScanReceiver extends BroadcastReceiver {
private static final String TAG = "WiFiScanReceiver";
systemInfo systemInfo;
public WiFiScanReceiver(systemInfo systemInfo) {
super();
this.systemInfo = systemInfo;
}
#Override
public void onReceive(Context c, Intent intent) {
List<ScanResult> results = systemInfo.wifi.getScanResults();
ScanResult bestSignal = null;
for (ScanResult result : results) {
if (bestSignal == null
|| WifiManager.compareSignalLevel(bestSignal.level,
result.level) < 0) bestSignal = result;
}
String message = String.format(
"%s networks found. %s is the strongest.", results.size(),
bestSignal.SSID);
Toast.makeText(systemInfo, message, Toast.LENGTH_LONG).show();
Log.d(TAG, "onReceive() message: " + message);
}
}
systemInfo.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class systemInfo extends Activity implements OnClickListener {
private static final String TAG = "WiFiDemo";
WifiManager wifi;
BroadcastReceiver receiver;
TextView textStatus;
Button buttonScan;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Setup UI
textStatus = (TextView) findViewById(R.id.textStatus);
buttonScan = (Button) findViewById(R.id.buttonScan);
buttonScan.setOnClickListener(this);
// Setup WiFi
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// Get WiFi status
WifiInfo info = wifi.getConnectionInfo();
textStatus.append("\n\nWiFi Status: " + info.toString());
// List available networks
List<WifiConfiguration> configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
textStatus.append("\n\n" + config.toString());
}
// Register Broadcast Receiver
if (receiver == null) receiver = new WiFiScanReceiver(this);
registerReceiver(receiver, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
Log.d(TAG, "onCreate()");
MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;
System.out.println("availableMegs:::::::::::" + availableMegs);
}
#Override
public void onStop() {
unregisterReceiver(receiver);
}
public void onClick(View view) {
Toast.makeText(this, "On Click Clicked. Toast to that!!!",
Toast.LENGTH_LONG).show();
if (view.getId() == R.id.buttonScan) {
Log.d(TAG, "onClick() wifi.startScan()");
wifi.startScan();
String ab = getInfo();
System.out.println("CPU INFORMATON:::::::::::::\n" + ab);
textStatus.append("CPU INFORMATON:::::::::::::\n" + ab);
}
}
private String getInfo() {
StringBuffer sb = new StringBuffer();
sb.append("abi: ").append(Build.CPU_ABI).append("\n");
if (new File("/proc/cpuinfo").exists()) {
try {
BufferedReader br = new BufferedReader(new FileReader(new File(
"/proc/cpuinfo")));
String aLine;
while ((aLine = br.readLine()) != null) {
sb.append(aLine + "\n");
}
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
permissions are
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
This gives me basic wifi information .But I want the hardware information ..
One important difference is the CPU architecture. Although almost all Android devices use ARM CPU, it comes with different versions, including armv5, armv5te, armv6, armv6 with VFP, armv7, armv7 with VFP, armv7 with neon etc.
If your question is how to obtain the hardware information about the WiFi chip, then answer is simple: Android does not provide this kind of data, except of MAC address (which, btw, is not really the hardware information).

How to read a selected text file from sdcard on android

i am new at android development and i need your help. I was locking at topics that are similar for my development but non of then help me.
So far i create functions that gets me the files from my sdcard and shows me the list of then.
That is working
this is the code for getting the paths on sdcard:
package com.seminarskirad;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
public class LoadActivity extends ListActivity{
private enum DISPLAYMODE{ ABSOLUTE, RELATIVE; }
private final DISPLAYMODE displayMode = DISPLAYMODE.ABSOLUTE;
private List<String> directoryEntries = new ArrayList<String>();
private File currentDirectory = new File("/");
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Browse(Environment.getExternalStorageDirectory());
}
private void upOneLevel(){
if(this.currentDirectory.getParent() != null)
this.Browse(this.currentDirectory.getParentFile());
}
private void Browse(final File aDirectory){
if (aDirectory.isDirectory()){
this.currentDirectory = aDirectory;
fill(aDirectory.listFiles());
}
}
private void fill(File[] files) {
this.directoryEntries.clear();
if(this.currentDirectory.getParent() != null)
this.directoryEntries.add("..");
switch(this.displayMode){
case ABSOLUTE:
for (File file : files){
this.directoryEntries.add(file.getPath());
}
break;
case RELATIVE: // On relative Mode, we have to add the current-path to the beginning
int currentPathStringLenght = this.currentDirectory.getAbsolutePath().length();
for (File file : files){
this.directoryEntries.add(file.getAbsolutePath().substring(currentPathStringLenght));
}
break;
}
ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.load, this.directoryEntries);
this.setListAdapter(directoryList);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
int selectionRowID = position;
String selectedFileString = this.directoryEntries.get(selectionRowID);
if(selectedFileString.equals("..")){
this.upOneLevel();
}else if(selectedFileString.equals()){ /// what to write here ???
this.readFile(); ///what to write here???
} else {
File clickedFile = null;
switch(this.displayMode){
case RELATIVE:
clickedFile = new File(this.currentDirectory.getAbsolutePath()
+ this.directoryEntries.get(selectionRowID));
break;
case ABSOLUTE:
clickedFile = new File(this.directoryEntries.get(selectionRowID));
break;
}
if(clickedFile.isFile())
this.Browse(clickedFile);
}
}
private void readFile() {
// what to write here???
}
Sorry i cant put the image because i dont have reputation, but when i run it on my emulator a get something like this:
/mnt/sdcard/kuzmanic.c
/mnt/sdcard/text.txt
/mnt/sdcard/DCIM
/mnt/sdcard/LOST.DIR
So what I want to do is when i click on the text.txt or kuzmanic.c file I want to open then in the same layout file, that is my load.xml file:
This is the code for the xml file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18sp">
</TextView>
What i need to write in my code and do I have to write anything in the manifest???
Try this code:
package com.javasamples;
import java.io.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
public class FileDemo2 extends Activity {
// GUI controls
EditText txtData;
Button btnWriteSDFile;
Button btnReadSDFile;
Button btnClearScreen;
Button btnClose;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// bind GUI elements with local controls
txtData = (EditText) findViewById(R.id.txtData);
txtData.setHint("Enter some lines of data here...");
btnWriteSDFile = (Button) findViewById(R.id.btnWriteSDFile);
btnWriteSDFile.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// write on SD card file data in the text box
try {
File myFile = new File("/sdcard/mysdfile.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append(txtData.getText());
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),
"Done writing SD 'mysdfile.txt'",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}// onClick
}); // btnWriteSDFile
btnReadSDFile = (Button) findViewById(R.id.btnReadSDFile);
btnReadSDFile.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// write on SD card file data in the text box
try {
File myFile = new File("/sdcard/mysdfile.txt");
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(
new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null) {
aBuffer += aDataRow + "\n";
}
txtData.setText(aBuffer);
myReader.close();
Toast.makeText(getBaseContext(),
"Done reading SD 'mysdfile.txt'",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}// onClick
}); // btnReadSDFile
btnClearScreen = (Button) findViewById(R.id.btnClearScreen);
btnClearScreen.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// clear text box
txtData.setText("");
}
}); // btnClearScreen
btnClose = (Button) findViewById(R.id.btnClose);
btnClose.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// clear text box
finish();
}
}); // btnClose
}// onCreate
}// AndSDcard
the layout file is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/widget28"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000ff"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="#+id/txtData"
android:layout_width="fill_parent"
android:layout_height="180px"
android:textSize="18sp" />
<Button
android:id="#+id/btnWriteSDFile"
android:layout_width="143px"
android:layout_height="44px"
android:text="1. Write SD File" />
<Button
android:id="#+id/btnClearScreen"
android:layout_width="141px"
android:layout_height="42px"
android:text="2. Clear Screen" />
<Button
android:id="#+id/btnReadSDFile"
android:layout_width="140px"
android:layout_height="42px"
android:text="3. Read SD File" />
<Button
android:id="#+id/btnClose"
android:layout_width="141px"
android:layout_height="43px"
android:text="4. Close" />
</LinearLayout>
I used this code to read a text file in SD card,
public class ReadFileSDCardActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.fileContent);
File dir = Environment.getExternalStorageDirectory();
//File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");
//Get the text file
File file = new File(dir,"text.txt");
// i have kept text.txt in the sd-card
if(file.exists()) // check if file exist
{
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Set the text
tv.setText(text);
}
else
{
tv.setText("Sorry file doesn't exist!!");
}
}
}
first you have to give an id to your textview into the load.xml file and define the textview inside a linear layout. like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
<TextView android:id="#+id/tv1
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18sp"/>
now you have to set the layout of your activity.you can do this in the onCreate() method only.
setContentView(R.layout.load);
now make a TextVew object like this.
TextView tview = (TextView) findViewById(R.id.tv1);
now you have to read the text file using FileInputStream and keep it into a string variable.
after that you can assign the string to the text view.
tview.setText(string variable name);

Categories

Resources