Appel d'une méthode d'une autre classe
Bonjour,
J'essaie d'appeler une méthode d'un autre classe, mais j'ai un plantage à l’exécution.
Merci d'avance pour votre aide.
Bernard
Appelant :
Code:
1 2 3 4
| public void updatetxt(View v) {
TextSMS monObjet = new TextSMS();
monObjet.TraitementText();
} |
Appelé :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| package com.androidexample.bloqueurcallsms;
import android.app.Activity;
import android.os.Environment;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class TextSMS extends Activity {
EditText tv1;
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// }
public void TraitementText() {
tv1 = (EditText) findViewById(R.id.editTextSMS);
setContentView(R.layout.activity_texte);
FileInputStream fis = null;
String BufferBlock = "";
File ContactsFolderDir = new File(Environment.getExternalStorageDirectory() + File.separator + "ABloquer");
String myFileTexteBloque = ContactsFolderDir + File.separator + "BlockSmsTexte.txt";
File filetxtbloque = new File(myFileTexteBloque);
try {
fis = new FileInputStream(filetxtbloque);
int content;
BufferBlock = "";
while ((content = fis.read()) != -1) {
// convert to char and display it
System.out.print((char) content);
BufferBlock = BufferBlock + (char) content;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
tv1 = (EditText) findViewById(R.id.editTextSMS);
tv1.setText(BufferBlock);
}
public void updatemessage(View v) {
tv1 = (EditText) findViewById(R.id.editTextSMS);
String Chaine = tv1.getText().toString();
// Toast.makeText(this, "Click updatemessage : " + Chaine, Toast.LENGTH_LONG).show();
WriteToFile(Chaine, "BlockSmsTexte.txt");
}
public void WriteToFile(String TheText, String dst) {
File ContactsFolderDir = new File(Environment.getExternalStorageDirectory() + File.separator + "ABloquer");
String myFileDst = ContactsFolderDir + File.separator + dst;
FileOutputStream fos = null;
File file;
if (!ContactsFolderDir.exists()) {
ContactsFolderDir.mkdirs();
}
byte[] bytesArray = TheText.getBytes();
try {
file = new File(myFileDst);
fos = new FileOutputStream(file);
fos.write(bytesArray);
fos.flush();
} catch (IOException ioe) {
Toast.makeText(getApplicationContext(), "Erreur Write " + ioe, Toast.LENGTH_LONG).show();
}
}
} |
Fichier AndoidManifest.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidexample.bloqueurcallsms"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="MyBlocker"
android:theme="@style/AppTheme">
<activity
android:name="com.androidexample.bloqueurcallsms.MyBlocker"
android:label="MyBlocker">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.androidexample.bloqueurcallsms.TextSMS"
android:label="TextSMS">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest> |