如何在线程android中使用后台通知

时间:2013-09-29 07:23:39

标签: android multithreading background notifications

我正在制作一个应用程序,它将在后台运行时将文件发送到客户端(另一个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循环我希望hava通知文件是send.i已经看过通知教程我已经实现了该教程。但问题是我完成了想要打开像

这样的活动
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)时,它会打开一个内容视图,如果我发表评论,我会打开一个简单的空白活动。并且我想在发送文件后发出一个简单的通知,即文件已经发送而没有打开活动

0 个答案:

没有答案