バックグラウンドで実行中にクライアント (別の Android デバイス) にファイルを送信するアプリを作成し、ファイルがバックグラウンドから送信されたことをサーバーに通知したいと考えています。サーバーが送信しているファイルはスレッド内にあります。 .
for (int i = 0; i < receivingTheFullPathOfFilesAndSendFilesToClient
.size(); i++) {
File f = new File(
receivingTheFullPathOfFilesAndSendFilesToClient.get(i));
FileInputStream fis = new FileInputStream(
receivingTheFullPathOfFilesAndSendFilesToClient.get(i));
long size = f.length();
Log.e("size Of FIle is :", "" + size);
sendData.writeObject(size);
while ((len = fis.read(buf)) != -1) {
sendData.write(buf, 0, len);
}
sendData.flush();
// sendData.reset();
fis.close();
}
その後、forループでファイルが送信されたことを通知したい.私は通知のチュートリアルを見てきましたが、そのチュートリアルを実装しました.しかし、問題は、次のようなアクティビティを開きたいことです.
public class StatusBar extends Activity implements OnClickListener {
NotificationManager mn;
static final int uniqueId=1394885;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.statusbar);
Button b = (Button) findViewById(R.id.bstatusbar);
b.setOnClickListener(this);
mn = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mn.cancel(uniqueId);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// if ypu want tp open another class change status bar in tutorial 189
Intent intent = new Intent(this, SimpleBrowser.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
String body="this is a meagae from travis,thanx for ur support";
String title="travis.c";
//need to craate a notification i.e what the time is
Notification n=new Notification(R.drawable.ic_launcher,body,System.currentTimeMillis() );
// add what details we want to our notification
n.setLatestEventInfo(this, title, body, pi);
n.defaults=Notification.DEFAULT_ALL;
mn.notify(uniqueId,n);
finish();
}
この setContentView(R.layout.statusbar) を使用するとコンテンツ ビューが開き、コメントすると単純な空のアクティビティが開きます。ファイルを送信した後、アクティビティを開かずに、ファイルが送信されたという簡単な通知が来るようにしたい