FTPを使用してビデオをアップロードしています。そのためにも通知を表示しています。通知をクリックすると、アプリケーション画面が表示されます。したがって、同じ画面が2回実行されます。だから私は戻るボタンを2回クリックする必要があります。これは避けたい。私を助けてください...
public class loadVideo extends AsyncTask<Void, Void, Void> {
String status = null;
FTPClient ftp = new FTPClient();
InputStream in = null;
int progress = 2;
String dbftpserver, dbftpusername, dbftpPassword, dbftpPort,
dbftpDirPath = null;
String hostName, username, password = null;
NotificationManager notificationManager = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
int id = 10;
@Override
protected Void doInBackground(Void... arg0) {
UUID uniqueKey = UUID.randomUUID();
fname = uniqueKey.toString();
Log.e("UNIQUE NAME", fname);
String strquery1 = "SELECT FTP_Server,FTP_Username,FTP_Password,FTP_PORT,FTP_Directory_Path FROM hwd_settings WHERE ID = 1 ";
Cursor mCursor = (MainscreenActivity.JEEMAHWDroidDB).rawQuery(
strquery1, null);
if (mCursor.getCount() != 0) {
mCursor.moveToLast();
for (int i = mCursor.getCount() - 1; i >= 0; i--) {
dbftpserver = mCursor.getString(0);
dbftpusername = mCursor.getString(1);
dbftpPassword = mCursor.getString(2);
dbftpPort = mCursor.getString(3);
dbftpDirPath = mCursor.getString(4);
}
}
hostName = dbftpserver;
username = dbftpusername;
password = dbftpPassword;
try {
ftp.connect(hostName);
ftp.login(username, password);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
ftp.changeWorkingDirectory(dbftpDirPath + "uploads");
int reply = ftp.getReplyCode();
System.out.println("Received Reply from FTP Connection:"
+ reply);
if (FTPReply.isPositiveCompletion(reply)) {
System.out.println("Connected Success");
doftpVideo();
} else {
Log.e("FTP", "CONNECTION ERROR");
finish();
Toast.makeText(getApplicationContext(),
"Unable to connect FTP", Toast.LENGTH_LONG).show();
}
return null;
} catch (Exception i) {
i.printStackTrace();
String temp = i.toString();
if (temp.equalsIgnoreCase("java.net.UnknownHostException: "
+ hostName)) {
showAlert();
}
}
return null;
}
private void showAlert() {
AlertDialog.Builder alert = new AlertDialog.Builder(
NewVideoActivity.this);
alert.setMessage("Unable to connect FTP");
alert.setPositiveButton(getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.cancel();
}
}).show();
}
public void doftpVideo() {
Intent intent1 = new Intent(NewVideoActivity.this,
MainscreenActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, intent1, 0);
Notification notification = new Notification();
final String location = selectedPath;
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor prefsEditor = prefs.edit();
try {
int icon = R.drawable.video_upload; // icon from resources
CharSequence tickerText = "Starting Video Upload"; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application
// Context
CharSequence contentTitle = "JEEMAHWDroid"; // expanded message
// title
CharSequence contentText = "Uploading " + strTitle; // expanded
// message
// text
notification = new Notification(icon, tickerText, when);
notification.flags = notification.flags
| Notification.FLAG_ONLY_ALERT_ONCE
| Notification.FLAG_NO_CLEAR;
notification.setLatestEventInfo(context, contentTitle,
contentText, pendingIntent);
notificationManager.notify(id, notification);
File f1 = new File(location);
in = new FileInputStream(f1);
ftp.storeFile(fname + "." + extension, in);
System.out.println("SUCCESS");
System.out.println("Video Title:" + strTitle
+ " is uploaded successfully");
System.out.println("Video Name:" + fname
+ " is uploaded successfully");
status = "completed";
prefsEditor.putString("status", status);
prefsEditor.commit();
String tempStatus = prefs.getString("status", null);
System.out.println("tempSTATUS-->>>" + tempStatus);
strUserName = prefs.getString(
getResources().getString(R.string.username), null);
strToken = prefs.getString(
getResources().getString(R.string.token), null);
url = prefs.getString("VALUE", null);
doftpImage();
doCreateRecord();
} catch (Exception i) {
i.printStackTrace();
}
return;
}