Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android线程中使用后台通知_Android_Multithreading_Background_Notifications - Fatal编程技术网

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

如何在android线程中使用后台通知,android,multithreading,background,notifications,Android,Multithreading,Background,Notifications,我正在制作一个应用程序,在后台运行时将文件发送到客户端(另一个android设备),我想向服务器显示文件已从后台发送的通知。服务器正在发送的文件位于线程中 for (int i = 0; i < receivingTheFullPathOfFilesAndSendFilesToClient .size(); i++) { File f = new File( receivingTheFullPa

我正在制作一个应用程序,在后台运行时将文件发送到客户端(另一个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();
        }
}
当我使用此setContentView(R.layout.statusbar)时,它会打开一个内容视图,如果我对其进行注释,则会打开一个简单的空白活动。我希望在发送文件后,会发出一个简单的通知,表明文件已发送,并且没有打开活动

不如改为发送一条简单的Toast消息?因为服务器将在后台运行,我希望显示客户端复制的文件列表。因此,您希望1)将文件从服务器发送到客户端2)对于以某种方式发送的每个文件通知服务器设备3)是否能够显示发送到客户端的文件列表?我想如果我完全了解你想要实现的目标,我可能会回答你的问题
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();

}