Skip to content

Commit 31503b6

Browse files
committed
增加上传
1 parent 74ab667 commit 31503b6

File tree

27 files changed

+437
-168
lines changed

27 files changed

+437
-168
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

andfix/src/main/java/com/example/andfix/AndFixService.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example.andfix;
22

3+
import android.app.IntentService;
34
import android.app.Service;
45
import android.content.Intent;
56
import android.os.Handler;
@@ -20,7 +21,7 @@
2021
import java.io.File;
2122
import java.util.HashMap;
2223

23-
public class AndFixService extends Service {
24+
public class AndFixService extends IntentService {
2425
private static final String TAG = AndFixService.class.getSimpleName();
2526
private static final String FILE_END = ".apatch";
2627
private static final int UPDATE_PATCH = 0x02;
@@ -45,24 +46,38 @@ public void handleMessage(Message msg) {
4546
}
4647
};
4748

49+
/**
50+
* Creates an IntentService. Invoked by your subclass's constructor.
51+
*
52+
* @param name Used to name the worker thread, important only for debugging.
53+
*/
54+
public AndFixService(String name) {
55+
super(name);
56+
}
57+
4858
@Nullable
4959
@Override
5060
public IBinder onBind(Intent intent) {
5161
return null;
5262
}
5363

64+
@Override
65+
protected void onHandleIntent(Intent intent) {
66+
mHandler.sendEmptyMessage(UPDATE_PATCH);
67+
}
68+
5469

5570
@Override
5671
public void onCreate() {
5772
super.onCreate();
5873
init();
5974
}
6075

61-
@Override
62-
public int onStartCommand(Intent intent, int flags, int startId) {
63-
mHandler.sendEmptyMessage(UPDATE_PATCH);
64-
return START_NOT_STICKY;
65-
}
76+
// @Override
77+
// public int onStartCommand(Intent intent, int flags, int startId) {
78+
// mHandler.sendEmptyMessage(UPDATE_PATCH);
79+
// return START_NOT_STICKY;
80+
// }
6681

6782
//完成文件目录的构造
6883
private void init() {
@@ -73,7 +88,7 @@ private void init() {
7388

7489
try {
7590
if (patchDir == null || !patchDir.exists()) {
76-
patchDir.mkdir();
91+
patchDir.mkdirs();
7792
}
7893
} catch (Exception e) {
7994
e.printStackTrace();

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
android:roundIcon="@mipmap/ic_launcher_round"
2222
android:supportsRtl="true"
2323
android:theme="@style/AppTheme">
24-
<activity android:name=".activity.AndFixActivity">
24+
<activity android:name=".activity.LoadingActivity">
2525
<intent-filter>
2626
<action android:name="android.intent.action.MAIN" />
2727

2828
<category android:name="android.intent.category.LAUNCHER" />
2929
</intent-filter>
3030
</activity>
31-
<activity android:name=".activity.MainActivity"></activity>
31+
<activity android:name=".activity.AndFixActivity"></activity>
3232

33-
<service
34-
android:name="com.example.andfix.AndFixService"
35-
/>
3633
</application>
3734

3835
</manifest>

app/src/main/java/com/example/kson/moduledemo/UserApi.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package com.example.kson.moduledemo;
22

33

4+
import com.example.kson.moduledemo.entity.UploadEntity;
5+
46
import java.util.HashMap;
7+
import java.util.List;
58

69
import io.reactivex.Observable;
10+
import okhttp3.MultipartBody;
711
import okhttp3.ResponseBody;
12+
import retrofit2.Response;
813
import retrofit2.http.FieldMap;
914
import retrofit2.http.FormUrlEncoded;
15+
import retrofit2.http.Multipart;
1016
import retrofit2.http.POST;
17+
import retrofit2.http.Part;
18+
import retrofit2.http.Url;
1119

1220
/**
1321
* Author:kson
@@ -19,4 +27,16 @@ public interface UserApi {
1927
@POST("user/login")
2028
@FormUrlEncoded
2129
Observable<ResponseBody> login(@FieldMap HashMap<String,String> params);
30+
31+
/**
32+
* 上传文件
33+
*
34+
* @param fileUrl
35+
* @return
36+
*/
37+
@POST
38+
@Multipart
39+
Observable<UploadEntity> uploadFile(@Url String fileUrl, @Part("content") String content,
40+
@Part() List<MultipartBody.Part> parts);
41+
2242
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.example.kson.moduledemo.activity;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
import android.support.v4.app.Fragment;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
11+
public class Fragemnt extends Fragment {
12+
13+
@Override
14+
public void onCreate(@Nullable Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
}
17+
18+
@Nullable
19+
@Override
20+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
21+
return super.onCreateView(inflater, container, savedInstanceState);
22+
}
23+
24+
@Override
25+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
26+
super.onActivityCreated(savedInstanceState);
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.kson.moduledemo.activity;
2+
3+
public class H {
4+
5+
6+
Callback callback;
7+
public void receive(){
8+
int i = 1;
9+
10+
if (callback!=null){
11+
callback.receive(i);
12+
}
13+
14+
15+
}
16+
17+
18+
public void setCallback(Callback callback) {
19+
this.callback = callback;
20+
}
21+
22+
interface Callback{
23+
void receive(int i);
24+
}
25+
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.example.kson.moduledemo.activity;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.support.v7.app.AppCompatActivity;
7+
8+
public class LoadingActivity extends AppCompatActivity {
9+
10+
@Override
11+
protected void onCreate(@Nullable Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
new H().receive();
14+
15+
startActivity(new Intent(this,MainActivity.class));
16+
}
17+
}

0 commit comments

Comments
 (0)