我正在制作一个应用程序,该应用程序将在后台运行时将文件发送到客户端(另一个 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) 它打开一个内容视图,如果我评论它我打开一个简单的空白活动。我希望在发送文件后会收到一个简单的通知,表明文件已发送且无需打开活动