Settings Non-English language password on android phone? - android

With Reference to this question on android stack, i have a solution to do which allows android phone to provide support for setting non-english language password.
My phones SRC is based on stock-android which is not allowing me to set password which is non-ascii standards like Hebrew.
Based from AOSP source code that handles the password input for lock screen, ChooseLockPassword.java, inside validatePassword() (line 292), here is a snippet that will show the "illegal character" message (from line 311):
// allow non control Latin-1 characters only
if (c < 32 || c > 127) {
return getString(R.string.lockpassword_illegal_character);
}
I have commented out this part but i don't think so this will work. [Waiting to be Flashed]
There are no such question for this condition, i need help for cracking the possibility for doing this any "Work around" will also do.

So after fighting few days i got a workaround by implementing my method for it.
private String validateHebrewPassword(String password)
{
if (password.length() < mPasswordMinLength) {
return getString(mIsAlphaMode ?
R.string.lockpassword_password_too_short
: R.string.lockpassword_pin_too_short, mPasswordMinLength);
}
if (password.length() > mPasswordMaxLength) {
return getString(mIsAlphaMode ?
R.string.lockpassword_password_too_long
: R.string.lockpassword_pin_too_long, mPasswordMaxLength + 1);
}
for (int i = 0; i < password.length(); i++)
{
char c = password.charAt(i);
System.out.println("Validate Hebrew Password Success "+ " Char "+c+" for password "+password+ " langauage "+locale);
}
return null;
}
And modiying its validatePasswor() caller a bit specific to hebrew like:
private void handleNext() {
final String pin = mPasswordEntry.getText().toString();
if (TextUtils.isEmpty(pin)) {
return;
}
String errorMsg = null;
if (mUiStage == Stage.Introduction)
{
String locale = java.util.Locale.getDefault().getLanguage();
if(locale.equals("iw")) //Specific Hebrew check
{
errorMsg = validateHebrewPassword(pin); //New Method
}
else
{
errorMsg = validatePassword(pin); //AOSP Method
}
if (errorMsg == null)
{
mFirstPin = pin;
mPasswordEntry.setText("");
updateStage(Stage.NeedToConfirm);
}
} else if (mUiStage == Stage.NeedToConfirm) {
if (mFirstPin.equals(pin)) {
final boolean isFallback = getActivity().getIntent().getBooleanExtra(
LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false);
mLockPatternUtils.clearLock(isFallback);
mLockPatternUtils.saveLockPassword(pin, mRequestedQuality, isFallback);
getActivity().setResult(RESULT_FINISHED);
getActivity().finish();
} else {
CharSequence tmp = mPasswordEntry.getText();
if (tmp != null) {
Selection.setSelection((Spannable) tmp, 0, tmp.length());
}
updateStage(Stage.ConfirmWrong);
}
}
if (errorMsg != null) {
showError(errorMsg, mUiStage);
}
}
private void updateUi() {
String password = mPasswordEntry.getText().toString();
final int length = password.length();
if (mUiStage == Stage.Introduction && length > 0) {
if (length < mPasswordMinLength) {
String msg = getString(mIsAlphaMode ? R.string.lockpassword_password_too_short
: R.string.lockpassword_pin_too_short, mPasswordMinLength);
mHeaderText.setText(msg);
mNextButton.setEnabled(false);
} else
{
String locale = java.util.Locale.getDefault().getLanguage();
String error = null;
if(locale.equals("iw")) //Specific Hebrew check
{
error = validateHebrewPassword(password); //New method
}
else
{
error = validatePassword(password); //AOSP Method
}
if (error != null) {
mHeaderText.setText(error);
mNextButton.setEnabled(false);
} else {
mHeaderText.setText(R.string.lockpassword_press_continue);
mNextButton.setEnabled(true);
}
}
} else {
mHeaderText.setText(mIsAlphaMode ? mUiStage.alphaHint : mUiStage.numericHint);
mNextButton.setEnabled(length > 0);
}
mNextButton.setText(mUiStage.buttonText);
}

Related

Intent Service blocks UI and causes ANR

I have to download some data as soon as user logs in to the app. I have put
-the network calls to download this data and
-the database transactions to write it to sqlite
in an intent service. The data is huge so, saving it to sqlite is taking time. But I'm wondering why the intent service is blocking the UI. I can't navigate through the application. If I click on any button nothing happens. If I click again, app just freezes and eventually causes ANR.
I was using Service earlier. As service runs on main thread, I'm using IntentService. I had concurrent AsyncTasks for downloading each set of data. Now I got rid of those AsyncTasks and handling all the network calls in onHandleIntent method. I'm testing on Android device of version 5.1.1(lollipop).
public class MastersSyncService extends IntentService {
private static final String TAG = "MastersSyncService";
private static final int CUSTOMERS_PAGE_LENGTH = 5000;
private Context mContext;
private DataSource dataSource;
private boolean isReset;
private ProgressDialog pDialog;
private int numOfCustReceived, pageNumber, customersVersion;
private AlertDialog alertDialog;
public MastersSyncService() {
super(TAG);
}
#Override
protected void onHandleIntent(Intent intent) {
mContext = MastersSyncService.this;
dataSource = new DataSource(mContext);
if (intent.getExtras() != null) {
isReset = intent.getBooleanExtra("isReset", false);
}
customersVersion = dataSource.customers.getVersion();
if (customersVersion == 0) {
dataSource.customers.truncateTable();
}
downloadPackingDataMasters();
downloadCommoditiesMasters(); //makes a network call and writes some simple data to sqlite
downloadPaymentTypesMasters(); //makes a network call and writes some simple data to sqlite
downloadReasonsMasters(); //makes a network call and writes some simple data to sqlite
downloadMeasurementTypesMasters(); //makes a network call and writes some simple data to sqlite
downloadDocketsMasters(); //makes a network call and writes some simple data to sqlite
downloadContractsMasters(); //makes a network call and writes some simple data to sqlite
downloadBookingModesMasters(); //makes a network call and writes some simple data to sqlite
downloadPincodeMasters(); //makes a network call and writes some simple data to sqlite
downloadCustomersMasters(); //this method has a recursive network call with pagination. Takes a lot of time
}
public void downloadCustomersMasters() {
try {
Globals.lastErrMsg = "";
String url = VXUtils.getCustomersUrl(customersVersion, pageNumber);
Utils.logD("Log 1");
InputStream inputStream = HttpRequest.getInputStreamFromUrlRaw(url, mContext);
if (inputStream != null) {
pageNumber++;
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
dataSource.beginTransaction();
String line = null;
while ((line = reader.readLine()) != null) {
if (Utils.isValidString(line)) {
numOfCustReceived++;
Utils.logD("line from InputStream: " + line);
parseCustomer(line);
}
}
dataSource.endTransaction();
} else {
numOfCustReceived = 0;
Utils.logD(TAG + " InputStream is null");
}
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("Exception while reading input " + ioe);
} catch (Exception e) {
e.printStackTrace();
if (!Utils.isValidString(Globals.lastErrMsg))
Globals.lastErrMsg = e.toString();
if (Globals.lastErrMsg.equalsIgnoreCase("null"))
Globals.lastErrMsg = getString(R.string.server_not_reachable);
}
if (numOfCustReceived >= CUSTOMERS_PAGE_LENGTH) {
downloadCustomersMasters();
} else {
if (!Utils.isValidString(Globals.lastErrMsg) && pDialog != null && pDialog.isShowing()) {
Utils.updateTimeStamp(mContext, Constants.CUSTOMERS_DATE_PREF);
}
}
}
public void downloadPackingDataMasters() {
try {
Globals.lastErrMsg = "";
int version = dataSource.packingData.getVersion();
String url = VXUtils.getPackingDataUrl(version); //, imei, versionCode + ""
Utils.logD("Log 1");
PackingDataResponse response = (PackingDataResponse) HttpRequest
.getInputStreamFromUrl(url, PackingDataResponse.class,
mContext);
if (response != null) {
Utils.logD("Log 4");
Utils.logD(response.toString());
if (response.isStatus()) {
List<PackingDataModel> data = response.getData();
if (Utils.isValidArrayList((ArrayList<?>) data)) {
if (isReset)
dataSource.packingData.truncateTable();
int val = dataSource.packingData.savePackingData(data, version);
}
} else {
Globals.lastErrMsg = response.getMessage();
}
}
} catch (Exception e) {
if (!Utils.isValidString(Globals.lastErrMsg))
Globals.lastErrMsg = e.toString();
if (Globals.lastErrMsg.equalsIgnoreCase("null"))
Globals.lastErrMsg = getString(R.string.server_not_reachable);
}
if (!Utils.isValidString(Globals.lastErrMsg)) {
Utils.updateTimeStamp(mContext, Constants.PACKING_DATE_PREF);
}
}
private final char DEFAULT_QUOTE_CHARACTER = '"';
private final char DEFAULT_SEPARATOR_CHARACTER = ',';
private void parseCustomer(String line) {
char quotechar = DEFAULT_QUOTE_CHARACTER;
char separator = DEFAULT_SEPARATOR_CHARACTER;
if (line == null) {
return;
}
List<String> tokensOnThisLine = new ArrayList<String>();
StringBuffer sb = new StringBuffer();
boolean inQuotes = false;
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
if (c == quotechar) {
if (inQuotes && line.length() > (i + 1)
&& line.charAt(i + 1) == quotechar) {
sb.append(line.charAt(i + 1));
i++;
} else {
inQuotes = !inQuotes;
if (i > 2 && line.charAt(i - 1) != separator
&& line.length() > (i + 1)
&& line.charAt(i + 1) != separator) {
sb.append(c);
}
}
} else if (c == separator && !inQuotes) {
if (Utils.isValidString(sb.toString())) {
String str = sb.toString().trim();
tokensOnThisLine.add(str);
} else {
tokensOnThisLine.add(sb.toString());
}
sb = new StringBuffer();
} else {
sb.append(c);
}
}
if (Utils.isValidString(sb.toString())) {
String str = sb.toString().trim();
tokensOnThisLine.add(str);
} else {
tokensOnThisLine.add(sb.toString());
}
int customerId = Integer.parseInt(tokensOnThisLine.get(0));
String custName = tokensOnThisLine.get(2);
Utils.logD("CUST: " + customerId + " " + custName);
dataSource.customers.saveCustomerDirect(
customerId,
tokensOnThisLine.get(1),
custName,
tokensOnThisLine.get(3),
tokensOnThisLine.get(4),
tokensOnThisLine.get(5),
tokensOnThisLine.get(6),
tokensOnThisLine.get(7),
Integer.parseInt(tokensOnThisLine.get(8)),
Integer.parseInt(tokensOnThisLine.get(9)),
Integer.parseInt(tokensOnThisLine.get(10)),
Integer.parseInt(tokensOnThisLine.get(11)),
Integer.parseInt(tokensOnThisLine.get(12)));
}
Downloading data is taking several minutes. I can't make the user wait for such long time. Please suggest how to make the UI interactive while the data is being downloaded in the background. Or please suggest ways to save huge number of records to sqlite quickly

Watson unity android bad recognition

Guys I'm using Unity and Watson to make and vr app that accepts voice commands. I'm using the ExampleStreaming.cs provided with the asset but the recognition is terrible. I change the language model to Portuguese on the code. I'm using Samsung galaxy s7 on gear vr with the mic plugged in. I guess the app is using the cellphone mic and not the plugged one. Any help here.
Here's the code
private int _recordingRoutine = 0;
private string _microphoneID = null;
private AudioClip _recording = null;
private int _recordingBufferSize = 1;
private int _recordingHZ = 22050;
private SpeechToText _service;
public GolemController GolemControllerObj;
void Start()
{
LogSystem.InstallDefaultReactors();
Runnable.Run(CreateService());
}
private IEnumerator CreateService()
{
// Create credential and instantiate service
Credentials credentials = null;
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
{
// Authenticate using username and password
credentials = new Credentials(_username, _password, _serviceUrl);
}
else if (!string.IsNullOrEmpty(_iamApikey))
{
// Authenticate using iamApikey
TokenOptions tokenOptions = new TokenOptions()
{
IamApiKey = _iamApikey,
IamUrl = _iamUrl
};
credentials = new Credentials(tokenOptions, _serviceUrl);
// Wait for tokendata
while (!credentials.HasIamTokenData())
yield return null;
}
else
{
throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service.");
}
_service = new SpeechToText(credentials);
_service.StreamMultipart = true;
_service.RecognizeModel="pt-BR_BroadbandModel";
Active = true;
StartRecording();
}
public bool Active
{
get { return _service.IsListening; }
set
{
if (value && !_service.IsListening)
{
_service.DetectSilence = true;
_service.EnableWordConfidence = true;
_service.EnableTimestamps = true;
_service.SilenceThreshold = 0.01f;
_service.MaxAlternatives = 0;
_service.EnableInterimResults = true;
_service.OnError = OnError;
_service.InactivityTimeout = -1;
_service.ProfanityFilter = false;
_service.SmartFormatting = true;
_service.SpeakerLabels = false;
_service.WordAlternativesThreshold = null;
_service.StartListening(OnRecognize, OnRecognizeSpeaker);
}
else if (!value && _service.IsListening)
{
_service.StopListening();
}
}
}
private void StartRecording()
{
if (_recordingRoutine == 0)
{
UnityObjectUtil.StartDestroyQueue();
_recordingRoutine = Runnable.Run(RecordingHandler());
}
}
private void StopRecording()
{
if (_recordingRoutine != 0)
{
Microphone.End(_microphoneID);
Runnable.Stop(_recordingRoutine);
_recordingRoutine = 0;
}
}
private void OnError(string error)
{
Active = false;
Log.Debug("ExampleStreaming.OnError()", "Error! {0}", error);
}
private IEnumerator RecordingHandler()
{
Log.Debug("ExampleStreaming.RecordingHandler()", "devices: {0}", Microphone.devices);
_recording = Microphone.Start(_microphoneID, true, _recordingBufferSize, _recordingHZ);
yield return null; // let _recordingRoutine get set..
if (_recording == null)
{
StopRecording();
yield break;
}
bool bFirstBlock = true;
int midPoint = _recording.samples / 2;
float[] samples = null;
while (_recordingRoutine != 0 && _recording != null)
{
int writePos = Microphone.GetPosition(_microphoneID);
if (writePos > _recording.samples || !Microphone.IsRecording(_microphoneID))
{
Log.Error("ExampleStreaming.RecordingHandler()", "Microphone disconnected.");
StopRecording();
yield break;
}
if ((bFirstBlock && writePos >= midPoint)
|| (!bFirstBlock && writePos < midPoint))
{
// front block is recorded, make a RecordClip and pass it onto our callback.
samples = new float[midPoint];
_recording.GetData(samples, bFirstBlock ? 0 : midPoint);
AudioData record = new AudioData();
record.MaxLevel = Mathf.Max(Mathf.Abs(Mathf.Min(samples)), Mathf.Max(samples));
record.Clip = AudioClip.Create("Recording", midPoint, _recording.channels, _recordingHZ, false);
record.Clip.SetData(samples, 0);
_service.OnListen(record);
bFirstBlock = !bFirstBlock;
}
else
{
// calculate the number of samples remaining until we ready for a block of audio,
// and wait that amount of time it will take to record.
int remaining = bFirstBlock ? (midPoint - writePos) : (_recording.samples - writePos);
float timeRemaining = (float)remaining / (float)_recordingHZ;
yield return new WaitForSeconds(timeRemaining);
}
}
yield break;
}
private void OnRecognize(SpeechRecognitionEvent result, Dictionary<string, object> customData)
{
if (result != null && result.results.Length > 0)
{
foreach (var res in result.results)
{
foreach (var alt in res.alternatives)
{
string text = string.Format("{0} ({1}, {2:0.00})\n", alt.transcript, res.final ? "Final" : "Interim", alt.confidence);
Log.Debug("ExampleStreaming.OnRecognize()", text);
ResultsField.text = text;
if(res.final == true)
{
GolemControllerObj.GolemActions(alt.transcript);
}
}
if (res.keywords_result != null && res.keywords_result.keyword != null)
{
foreach (var keyword in res.keywords_result.keyword)
{
Log.Debug("ExampleStreaming.OnRecognize()", "keyword: {0}, confidence: {1}, start time: {2}, end time: {3}", keyword.normalized_text, keyword.confidence, keyword.start_time, keyword.end_time);
}
}
if (res.word_alternatives != null)
{
foreach (var wordAlternative in res.word_alternatives)
{
Log.Debug("ExampleStreaming.OnRecognize()", "Word alternatives found. Start time: {0} | EndTime: {1}", wordAlternative.start_time, wordAlternative.end_time);
foreach(var alternative in wordAlternative.alternatives)
Log.Debug("ExampleStreaming.OnRecognize()", "\t word: {0} | confidence: {1}", alternative.word, alternative.confidence);
}
}
}
}
}
private void OnRecognizeSpeaker(SpeakerRecognitionEvent result, Dictionary<string, object> customData)
{
if (result != null)
{
foreach (SpeakerLabelsResult labelResult in result.speaker_labels)
{
Log.Debug("ExampleStreaming.OnRecognize()", string.Format("speaker result: {0} | confidence: {3} | from: {1} | to: {2}", labelResult.speaker, labelResult.from, labelResult.to, labelResult.confidence));
}
}
}

Check if a string is alphanumeric

I'm trying to check if a string is alphanumeric or not. I tried many things given in other posts but to no avail. I tried StringUtils.isAlphanumeric(), a library from Apache Commons but failed. I tried regex also from this link but that too didn't worked. Is there a method to check if a string is alphanumeric and returns true or false according to it?
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = fullnameet.getText().toString();
String numRegex = ".*[0-9].*";
String alphaRegex = ".*[A-Z].*";
if (text.matches(numRegex) && text.matches(alphaRegex)) {
System.out.println("Its Alphanumeric");
}else{
System.out.println("Its NOT Alphanumeric");
}
}
});
If you want to ascertain that your string is both alphanumeric and contains both numbers and letters, then you can use the following logic:
.*[A-Za-z].* check for the presence of at least one letter
.*[0-9].* check for the presence of at least one number
[A-Za-z0-9]* check that only numbers and letters compose this string
String text = fullnameet.getText().toString();
if (text.matches(".*[A-Za-z].*") && text.matches(".*[0-9].*") && text.matches("[A-Za-z0-9]*")) {
System.out.println("Its Alphanumeric");
} else {
System.out.println("Its NOT Alphanumeric");
}
Note that we could handle this with a single regex but it would likely be verbose and possibly harder to maintain than the above answer.
Original from here
String myString = "qwerty123456";
System.out.println(myString.matches("[A-Za-z0-9]+"));
String myString = "qwerty123456";
if(myString.matches("[A-Za-z0-9]+"))
{
System.out.println("Alphanumeric");
}
if(myString.matches("[A-Za-z]+"))
{
System.out.println("Alphabet");
}
try this
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Pattern p = Pattern.compile("[^a-zA-Z0-9]");
boolean hasSpecialChar = p.matcher(edittext.getText().toString()).find();
if (!edittext.getText().toString().trim().equals("")) {
if (hasSpecialChar) {
Toast.makeText(MainActivity.this, "not Alphanumeric", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Its Alphanumeric", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(MainActivity.this, "Empty value of edit text", Toast.LENGTH_SHORT).show();
}
}
});
This is the code to check if the string is alphanumeric or not. For more details check Fastest way to check a string is alphanumeric in Java
public class QuickTest extends TestCase {
private final int reps = 1000000;
public void testRegexp() {
for(int i = 0; i < reps; i++)
("ab4r3rgf"+i).matches("[a-zA-Z0-9]");
}
public void testIsAlphanumeric2() {
for(int i = 0; i < reps; i++)
isAlphanumeric2("ab4r3rgf"+i);
}
public boolean isAlphanumeric2(String str) {
for (int i=0; i<str.length(); i++) {
char c = str.charAt(i);
if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a)
return false;
}
return true;
}
}
While there are many ways to skin this cat, I prefer to wrap such code into reusable extension methods that make it trivial to do going forward. When using extension methods, you can also avoid RegEx as it is slower than a direct character check. I like using the extensions in the Extensions.cs NuGet package. It makes this check as simple as:
Add the https://www.nuget.org/packages/Extensions.cs package to your project.
Add "using Extensions;" to the top of your code.
"smith23#".IsAlphaNumeric() will return False whereas "smith23".IsAlphaNumeric() will return True. By default the .IsAlphaNumeric() method ignores spaces, but it can also be overridden such that "smith 23".IsAlphaNumeric(false) will return False since the space is not considered part of the alphabet.
Every other check in the rest of the code is simply MyString.IsAlphaNumeric().
Your example code would become as simple as:
using Extensions;
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = fullnameet.getText().toString();
//String numRegex = ".*[0-9].*";
//String alphaRegex = ".*[A-Z].*";
//if (text.matches(numRegex) && text.matches(alphaRegex)) {
if (text.IsAlphaNumeric()) {
System.out.println("Its Alphanumeric");
}else{
System.out.println("Its NOT Alphanumeric");
}
}
});

How to get Contacts Presence status from LinphoneFriend?

I have uses linphone library latest version. I want to display sip contacts status. here is my code.
LinphoneFriend[] friends = LinphoneManager.getLc().getFriendList();
if (!ContactsManager.getInstance().isContactPresenceDisabled() && friends != null && contact.hasAddress()) {
friendStatus.setVisibility(View.VISIBLE);
String friendSipAddress = "";
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
if (noa.isSIPAddress()) {
friendSipAddress = noa.getValue();
}
}
LinphoneFriend friend = null;
for (int i = 0; i < friends.length; i++) {
Log.e("Friend","Addr " + friends[i].getAddress().asStringUriOnly());
Log.e("Friend","Name " + friends[i].getAddress().getDisplayName());
if (friends[i].getAddress().asStringUriOnly().equalsIgnoreCase(friendSipAddress)) {
friend = friends[i];
break;
}
}
if(friend!=null) {
PresenceModel presenceModel = friend.getPresenceModel();
if (presenceModel != null) {
//PresenceActivityType presenceActivity = friends[0].getPresenceModel().getActivity().getType();
PresenceActivityType presenceActivity = presenceModel.getActivity().getType();
android.util.Log.e("Linphone",friend.getName()+" " + presenceActivity);
if (presenceActivity == PresenceActivityType.Online) {
friendStatus.setImageResource(R.drawable.led_connected);
} else if (presenceActivity == PresenceActivityType.Busy) {
friendStatus.setImageResource(R.drawable.led_error);
} else if (presenceActivity == PresenceActivityType.Away) {
friendStatus.setImageResource(R.drawable.led_inprogress);
} else if (presenceActivity == PresenceActivityType.OnThePhone) {
friendStatus.setImageResource(R.drawable.on_phone);
} else if (presenceActivity == PresenceActivityType.Offline) {
friendStatus.setImageResource(R.drawable.led_disconnected);
} else {
friendStatus.setImageResource(R.drawable.led_disconnected);
}
} else {
friendStatus.setImageResource(R.drawable.led_error);
//Log.e("Linphone", "led_error");
}
} else {
//Log.e("Friend","friend null");
}
} else {
Log.e("Friend","friend visibility gone");
friendStatus.setVisibility(View.INVISIBLE);
}
But LinphoneFriend object always give null PresenceModel. How to get presencemodel with status from linphonefriend?

Cannot receive attachment from Hotmail with Javamail

I can access Hotmail with Javamail.jar on Android. I want to receive a mail's attachment with Hotmail, this code is working for Gmail but with Hotmail is not working. Why it is not filling the disposition, so "dosyaIsmiEkDurumu" is not filling and is falling into the catch because of that.
Is there other code samples for access attachments on Hotmail, or why am I doing wrong with this code?
public void EkDosyaIsim(Part part) throws IOException,
MessagingException {
if (part.isMimeType("multipart/*")) {
Multipart mp = (Multipart) part.getContent();
for (int i = 0; i < mp.getCount(); i++) {
System.out.println("64 : [" + mp.getCount() + "] δΈͺ/n");
BodyPart mpart = mp.getBodyPart(i);
String disposition = mpart.getDisposition();
if ((disposition != null)
&& ((disposition.equals("ATTACHMENT")) || (disposition
.equals("INLINE")))) {
dosyaIsmiEkDurumu = mpart.getFileName();
if(dosyaIsmiEkDurumu != null)
{
dosyaIsmiDizi[k] = dosyaIsmiEkDurumu;
k++;
}
if (dosyaIsmiEkDurumu.toLowerCase().indexOf("gb2312") != -1) {
dosyaIsmiEkDurumu = MimeUtility.decodeText(dosyaIsmiEkDurumu);
}
} else if (mpart.isMimeType("multipart/*")) {
EkDosyaIsim(mpart);
} else
{
if ((dosyaIsmiEkDurumu != null)
&& (dosyaIsmiEkDurumu.toLowerCase().indexOf("GB2312") != -1)) {
dosyaIsmiEkDurumu = MimeUtility.decodeText(dosyaIsmiEkDurumu);
}
}
}
} else if (part.isMimeType("message/rfc822"))
{
EkDosyaIsim((Part) part.getContent());
}
}
The disposition is "advice", it's not guaranteed to be there even in messages that have attachments. See the JavaMail FAQ for more information on handling messages with attachments.

Categories

Resources