huangxinbao

add chat

正在显示 26 个修改的文件 包含 736 行增加177 行删除
... ... @@ -32,24 +32,25 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':xdy')
compile files('libs/pldroid-player-1.5.1.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:design:25.3.1'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile project(':xdy')
compile 'com.rockerhieu.emojicon:library:1.3.1'
compile 'org.kymjs.kjframe:kjframe:2.6'
compile 'io.reactivex:rxjava:1.0.9'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'me.yokeyword:fragmentation:0.10.3'
compile files('libs/pldroid-player-1.5.1.jar')
compile 'com.qiniu:happy-dns:0.2.+'
compile 'com.android.support:support-v4:25.3.1'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
... ...
... ... @@ -26,11 +26,10 @@
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".application.XdyApplicaiton"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
... ...
... ... @@ -36,6 +36,7 @@ import com.mang.xdy.demo.bean.VideoOrAudioStopEntity;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.dialog.LoginDialog;
import com.mang.xdy.demo.widget.view.NoScrollViewPager;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.UIUtils;
import com.mang.xdy.utils.XdyLogUtil;
... ... @@ -65,7 +66,8 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
private String username = "";
private String userpwd = "";
private SimpleFragmentPagerAdapter pagerAdapter;
private ViewPager viewPager;
@BindView(R.id.viewpager)
NoScrollViewPager viewPager;
private TabLayout tabLayout;
@BindView(R.id.surfaceview_playVideo)
SurfaceView surfaceviewPlayVideo;
... ... @@ -75,6 +77,12 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
private ProgressDialog mProgressDialog;
@BindView(R.id.img_playVideo_replay)
PLVideoTextureView mVideoView;
private String playVideoOrAudioId="";
//视频模式还是音频模式
private boolean isVideoMode=true;
/*mcu断开或者网络原因为false*/
private boolean isDefaultExit=true;
private AlertDialog mErrorDialog;
//TODO 默认回放
private boolean replay = true;
private Handler mmHandler = new Handler() {
... ... @@ -83,28 +91,39 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
super.handleMessage(msg);
ResponseEntity responseEntity = (ResponseEntity) msg.obj;
switch (responseEntity.getType()) {
case Constants.CLASS_EXIT:
xdySdk.removeAll();
ToastUtil.showToast("退出课堂",VideoPlayActivity.this);
progressDialogDismiss();
exit();
break;
case Constants.ERROR_CODE:
handError(responseEntity.getType(), responseEntity.getParam());
break;
case Constants.CLASS_INIT_SUCCESS:
String login = responseEntity.getParam();
parseJoinClass(login, true);
ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
// ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
break;
case Constants.CLASS_JOIN_SUCCESS:
//加入课堂成功
progressDialogDismiss();
UIUtils.closeDialog(mLoginDialog);
ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
// ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
String userJson = responseEntity.getParam();
SPUtil.putString(VideoPlayActivity.this, Constants.CLASS_JOIN_SUCCESS, userJson);
break;
case Constants.VIDEO_PLAY:
//播放视频
playVideoOrAudioId=responseEntity.getParam();
isVideoMode=true;
playVideo(responseEntity.getParam());
break;
case Constants.AUDIO_PLAY:
//播放音频
isVideoMode=false;
playVideoOrAudioId=responseEntity.getParam();
playAudio(responseEntity.getParam());
break;
case Constants.VIDEO_STOP:
... ... @@ -113,11 +132,12 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
//停止播放
stopPlay(responseEntity.getParam());
break;
case "video_success":
case Constants.PLAY_SUCCESS:
//自定义消息 播放视频音频都通过这个来判断
img_playVideo_novideo.setVisibility(View.GONE);
break;
}
}
};
... ... @@ -128,7 +148,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮
setContentView(R.layout.activity_video_play);
ButterKnife.bind(this);
XdySdk.init(this);
// XdySdk.init(this);
xdySdk = XdySdk.getXdyInstance();
xdySdk.add(this);
init();
... ... @@ -142,30 +162,30 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
btn_videoPlay_exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// xdySdk.api("leaveClass", "");
xdySdk.api("leaveClass", "");
//
// xdySdk.remove(VideoPlayActivity.this);
// xdySdk.removeAll();
// UIUtils.closeDialog(mLoginDialog);
// VideoPlayActivity.super.onBackPressed();
// Exit();
String id="initRecordPlayback";
String param="{\n" +
" \"classId\": 479270427 ,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String ss=XdyStringUtils.stringToJson(param,true);
xdySdk.api(id,ss);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
xdySdk.api("startRecordPlayback", "");
}
}, 200);
// exit();
// String id="initRecordPlayback";
// String param="{\n" +
// " \"classId\": 479270427 ,\n" +
// " \"portal\": \"112.126.80.182:90\",\n" +
// " \"userRole\": \"normal\",\n" +
// " \"userName\": \"\",\n" +
// " \"userId\": 0\n" +
// "}";
// String ss=XdyStringUtils.stringToJson(param,true);
// xdySdk.api(id,ss);
// mHandler.postDelayed(new Runnable() {
// @Override
// public void run() {
// xdySdk.api("startRecordPlayback", "");
// }
// }, 200);
}
});
... ... @@ -173,10 +193,10 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
public void setTablayout() {
pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this);
viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(pagerAdapter);
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
// tabLayout.setupWithViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager,false);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
}
... ... @@ -282,15 +302,12 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
xdySdk.onPlayDestroy();
xdySdk.api("leaveClass", "");
//
// xdySdk.remove(VideoPlayActivity.this);
xdySdk.removeAll();
//如果收到class_exit 就执行,退出界面
UIUtils.closeDialog(mLoginDialog);
// VideoPlayActivity.super.onBackPressed();
Exit();
exit();
// progressDialogShow();
}
})
.create();
... ... @@ -329,7 +346,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
case "207":
case "208":
ToastUtil.showToastshort(errorEntity.getReson(), this);
Exit();
exit();
break;
case "300":
case "301":
... ... @@ -342,20 +359,39 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
case "20000":
ToastUtil.showToastshort(errorEntity.getReson(), this);
isDefaultExit=false;
showErrorDialog();
// ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
}
}
@Override
protected void onPause() {
super.onPause();
xdySdk.onPlayStop(playVideoOrAudioId);
}
@Override
protected void onResume() {
super.onResume();
if(isVideoMode) {
playVideo(playVideoOrAudioId);
}else{
playAudio(playVideoOrAudioId);
}
}
/**
* 错误情况退出
*/
public void Exit() {
public void exit() {
xdySdk.remove(this);
UIUtils.closeDialog(mLoginDialog);
// mmHandler.removeCallbacksAndMessages(null);
xdySdk.onPlayPauseAll();
mmHandler.removeCallbacksAndMessages(null);
this.finish();
}
... ... @@ -387,10 +423,32 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
}
}
}
public void showErrorDialog() {
if(isDefaultExit){
return;
}
if (mErrorDialog != null)
return;
mErrorDialog = new AlertDialog.Builder(this)
.setTitle("退出")
.setMessage("您设备的网络属于断开状态,请重新进入")
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
exit();
}
})
.create();
mErrorDialog.setCanceledOnTouchOutside(false);
mErrorDialog.show();
}
@Override
public void observerUpData(String type, String parameter) {
XdyLogUtil.e(TAG + "observer:", Thread.currentThread().getId() + "");
XdyLogUtil.e(TAG + "observer:", Thread.currentThread().getId() + "type:"+type);
ResponseEntity responseEntity = new ResponseEntity(type, parameter);
Message message = Message.obtain();
message.obj = responseEntity;
... ... @@ -412,7 +470,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
private RelativeLayout mPauseContainer;
private TextView mClassName;
private SurfaceView mSurfaceView = null;
private AlertDialog mErrorDialog;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
@Override
... ...
... ... @@ -33,6 +33,7 @@ package com.mang.xdy.demo.activity;
import com.mang.xdy.demo.bean.AudioPlayBean;
import com.mang.xdy.demo.bean.ChatBean;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.ErrorEntity;
import com.mang.xdy.demo.bean.InitClassSuccessEntity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.LiveBean;
... ... @@ -43,6 +44,7 @@ package com.mang.xdy.demo.activity;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.dialog.LoginDialog;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.UIUtils;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
... ... @@ -51,7 +53,7 @@ package com.mang.xdy.demo.activity;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class VideoPublisherActivity extends AppCompatActivity {
public class VideoPublisherActivity extends AppCompatActivity implements ObserverListener{
private final static String TAG = "VideoPlayActivity";
@BindView(R.id.btn_videoPlay_pubsherVideo)
Button btnVideoPlayPubsherVideo;
... ... @@ -120,6 +122,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
btn_videoPlay_publisherAudio.setVisibility(View.GONE);
// setTablayout();
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
init();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
... ... @@ -248,8 +251,17 @@ private LoginDialog mLoginDialog;
}
@Override
protected void onPause() {
super.onPause();
xdySdk.onPublisherPause();
}
@Override
protected void onResume() {
super.onResume();
xdySdk.onPublisherResume();
}
@Override
protected void onDestroy() {
... ... @@ -278,6 +290,61 @@ private LoginDialog mLoginDialog;
break;
}
}
@Override
public void observerUpData(final String type, final String parameter) {
handler.post(new Runnable() {
@Override
public void run() {
handError(type,parameter);
}
});
}
public void handError(String errorId, String errorMsg) {
ErrorEntity errorEntity = JsonUtil.parseJsonToBean(errorMsg, ErrorEntity.class);
if (errorEntity == null) {
return;
}
switch (errorEntity.getCode() + "") {
case "100":
case "101":
case "102":
case "103":
case "104":
case "105":
case "106":
case "107":
case "200":
case "201":
case "202":
case "203":
case "204":
case "205":
case "206":
case "207":
case "208":
ToastUtil.showToastshort(errorEntity.getReson(), this);
exit();
break;
case "300":
case "301":
break;
case "10000":
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
case "10001":
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
case "20000":
isDefaultExit=false;
showErrorDialog();
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
}
}
class EventHande implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
... ... @@ -315,8 +382,44 @@ private LoginDialog mLoginDialog;
}
}
/*mcu断开或者网络原因为false*/
private boolean isDefaultExit=true;
private android.support.v7.app.AlertDialog mErrorDialog;
public void showErrorDialog() {
// if(isDefaultExit){
// return;
// }
if (mErrorDialog != null)
return;
mErrorDialog = new android.support.v7.app.AlertDialog.Builder(this)
.setTitle("退出")
.setMessage("您设备的网络属于断开状态,请重新进入")
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
exit();
}
})
.create();
mErrorDialog.setCanceledOnTouchOutside(false);
mErrorDialog.show();
}
/**
* 错误情况退出
*/
public void exit() {
UIUtils.closeDialog(mLoginDialog);
// xdySdk.onPublisherStop();
xdySdk.remove(this);
handler.removeCallbacksAndMessages(null);
this.finish();
}
class PersonDialog extends Dialog {
public PersonDialog(Context context) {
this(context, false);
... ...
... ... @@ -276,13 +276,13 @@ public class DocFragment extends Fragment implements ObserverListener{
@Override
public void onDestroyView() {
super.onDestroyView();
xdySdk.remove(this);
if(mCanvasView!=null){
mCanvasView.clear();
}
if(bitmap!=null){
bitmap=null;
}
mHandler.removeCallbacksAndMessages(null);
// xdySdk.remove(this);
// if(mCanvasView!=null){
// mCanvasView.clear();
// }
// if(bitmap!=null){
// bitmap=null;
// }
// mHandler.removeCallbacksAndMessages(null);
}
}
... ...
package com.mang.xdy.demo.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mang.xdy.demo.R;
/**
* A simple {@link Fragment} subclass.
* Use the {@link PublishFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class PublishFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public PublishFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment PublishFragment.
*/
// TODO: Rename and change types and number of parameters
public static PublishFragment newInstance(String param1, String param2) {
PublishFragment fragment = new PublishFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_publish, container, false);
}
}
... ...
package com.mang.xdy.demo.widget.view;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* Created by abao on 2017/4/26.
*/
public class NoScrollViewPager extends ViewPager {
private boolean isPagingEnabled = true;
public NoScrollViewPager(Context context) {
super(context);
}
public NoScrollViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onInterceptTouchEvent(event);
}
public void setPagingEnabled(boolean b) {
this.isPagingEnabled = b;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (listener != null && ev.getAction() == MotionEvent.ACTION_DOWN) {
listener.onClick();
}
return super.dispatchTouchEvent(ev);
}
private OnRplayTouchListener listener;
public interface OnRplayTouchListener {
public void onClick();
}
public void setOnRplayTouchListener(OnRplayTouchListener listener) {
this.listener = listener;
}
}
... ...
... ... @@ -15,7 +15,7 @@
android:id="@+id/edt_home_classId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1184939098"/>
android:text="1573557360"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
... ... @@ -61,6 +61,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="推视频"
android:visibility="gone"
/>
... ... @@ -69,6 +70,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="推音频"
android:visibility="gone"
/>
</LinearLayout>
... ...
... ... @@ -10,7 +10,8 @@
<FrameLayout
android:id="@+id/fl_videoview_container"
android:layout_width="match_parent"
android:layout_height="10dp">
android:layout_height="1dp"
android:visibility="gone">
<com.pili.pldroid.player.widget.PLVideoTextureView
android:id="@+id/img_playVideo_replay"
... ... @@ -25,26 +26,34 @@
android:id="@+id/surfaceview_playVideo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/img_playVideo_novideo"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/novideo"
/>
android:layout_height="match_parent">
<ImageView
android:id="@+id/img_playVideo_novideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/novideo"
/>
<Button
android:id="@+id/btn_videoPlay_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:text="退出课堂,界面还在"
android:visibility="gone"
/>
</FrameLayout>
</RelativeLayout>
<Button
android:id="@+id/btn_videoPlay_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="退出课堂,界面还在"
/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<android.support.v4.view.ViewPager
<com.mang.xdy.demo.widget.view.NoScrollViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
... ... @@ -55,7 +64,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="invisible">
android:visibility="gone">
<include
layout="@layout/home_media_controller"
... ...
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mang.xdy.demo.fragment.PublishFragment">
<!-- TODO: Update blank fragment layout -->
<SurfaceView
android:id="@+id/sur_publish"
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="@string/hello_blank_fragment" />
<Button
android:id="@+id/btn_publish_gets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="获取推流地址,开始推流"
/>
<Button
android:id="@+id/btn_publish_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="停止推流"
/>
</FrameLayout>
... ...

12.4 KB | 宽: | 高:

25.7 KB | 宽: | 高:

  • 两方对比
  • 交换覆盖
  • 透明覆盖
<resources>
<string name="app_name">学点云</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
... ...
... ... @@ -30,10 +30,12 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
private final static String URL="http://h5.test.3mang.com/web/";
private SurfaceView surface;
private Button bt_stop;
private XdySdk xdySdk;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_threeivity);
xdySdk=XdySdk.getXdyInstance();
bt_three= (Button) findViewById(R.id.bt_three);
bt_video= (Button) findViewById(R.id.bt_video);
surface= (SurfaceView) findViewById(R.id.surface);
... ... @@ -83,7 +85,7 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
//// xdyPlayer.playVideo(url,surface);
// XdySdk.setAsyncApi("playAudio",url,null,Threeivity.this);
// XdySdk.setAsyncApi("playVideo",url,surface,Threeivity.this,new EventHande());
XdySdk.api("publishVideo",url,surface,Threeivity.this,new EventHande());
xdySdk.api("publishVideo",url,surface,Threeivity.this);
// xdyPlayer.playVideo("",surface);
// XdyPublisherCore xdyPublisherCore=new XdyPublisherCore(Threeivity.this);
... ... @@ -94,8 +96,10 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
bt_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
XdySdk.onPlayStop();
// xdySdk.onPlayStop();
// XdySdk.onPublisherStop();;
xdySdk.api("leaveClass","");
}
});
init();
... ... @@ -115,7 +119,7 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
case R.id.bt_paudio:
//开始推送音频
String url= "rtmp://player.daniulive.com:1935/hls/stream";;
XdySdk.setAsyncApi("publishAudio",url,surface,Threeivity.this);
xdySdk.api("publishAudio",url,surface,Threeivity.this);
break;
case R.id.bt_stopaudiopub:
//停止
... ... @@ -130,7 +134,7 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
" \"userId\": 0\n" +
"}";
String ss=StringUtils.stringToJson(param,true);
XdySdk.api(id,ss);
xdySdk.api(id,ss);
break;
case R.id.bt_back:
// String id="initRecordPlayback";
... ... @@ -143,7 +147,7 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
// " \"userId\": 0\n" +
// "}";
// String ss=StringUtils.stringToJson(param,true);
XdySdk.api(ids,"");
xdySdk.api(ids,"");
break;
case R.id.bt_stopReco:
// String isd="stopRecordPlayback";
... ... @@ -158,7 +162,7 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
String ids_new="getVideoPublishPath";
String tem="{ \"type\": \"live\"}";
String s= StringUtils.stringToJson(tem,true);
XdySdk.api(ids_new,s);
xdySdk.api(ids_new,s);
break;
... ... @@ -184,7 +188,7 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
// LogUtil.e("java_native",s+":"+s1);
// }
// });
XdySdk.api(id,parameter);
xdySdk.api(id,parameter);
// XdySdk.getXdyInstance().setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
// @Override
// public void onXdyAsyncMessageReceiver(String type, String response) {
... ... @@ -192,41 +196,41 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
// }
// });
XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
XdyLogUtil.e("学点云static", type + ":" + response);
// if ("video_play".equals(type)) {
// MessageBean messageBean = new Gson().fromJson(response, MessageBean.class);
// if (messageBean != null) {
//// Intent intent = new Intent(Threeivity.this, SmartPlayer.class);
//// intent.putExtra("url", messageBean.getRtmpUrl() + "");
//// startActivity(intent);
// Toast.makeText(Threeivity.this, messageBean.getRtmpUrl(), Toast.LENGTH_SHORT).show();
//// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface,Threeivity.this);
// XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
// @Override
// public void onXdyAsyncMessageReceiver(String type, String response) {
// XdyLogUtil.e("学点云static", type + ":" + response);
//// if ("video_play".equals(type)) {
//// MessageBean messageBean = new Gson().fromJson(response, MessageBean.class);
//// if (messageBean != null) {
////// Intent intent = new Intent(Threeivity.this, SmartPlayer.class);
////// intent.putExtra("url", messageBean.getRtmpUrl() + "");
////// startActivity(intent);
//// Toast.makeText(Threeivity.this, messageBean.getRtmpUrl(), Toast.LENGTH_SHORT).show();
////// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface,Threeivity.this);
//// }
//// }
// if("live".equals(type)){
//// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
// String url = XdyStringUtils.stringToJson(response);
// XdyLogUtil.e("调用任务了播视频了url:",""+url);
// String us=response.substring(1,response.length()-1);
// XdyLogUtil.e("调用任务了播视频了ursfdfl:",""+us);
// try {
//
// LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
//
// if (liveBean != null) {
// XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surface, Threeivity.this);
// XdyLogUtil.e("调用任务了播视频了","哈哈哈哈");
// }
// }catch (Exception e){
// XdyLogUtil.e("调用任务了播视频了e",""+e.getMessage());
// XdyLogUtil.e("调用任务了播视频了url:",""+url);
// }
// }
if("live".equals(type)){
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
String url = XdyStringUtils.stringToJson(response);
XdyLogUtil.e("调用任务了播视频了url:",""+url);
String us=response.substring(1,response.length()-1);
XdyLogUtil.e("调用任务了播视频了ursfdfl:",""+us);
try {
LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
if (liveBean != null) {
XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surface, Threeivity.this);
XdyLogUtil.e("调用任务了播视频了","哈哈哈哈");
}
}catch (Exception e){
XdyLogUtil.e("调用任务了播视频了e",""+e.getMessage());
XdyLogUtil.e("调用任务了播视频了url:",""+url);
}
}
}
});
// }
// });
}
public void playMedia(){
Intent intent = new Intent(Intent.ACTION_VIEW);
... ...
... ... @@ -20,6 +20,7 @@
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... ... @@ -34,6 +35,7 @@
android:name=".PLVideoTextureActivity"
android:theme="@style/AppThemeFullscreen" />
<activity android:name=".VideoFileActivity" />
<activity android:name="com.xdy.abao.ClassexitActivity"></activity>
</application>
</manifest>
\ No newline at end of file
... ...
package com.xdy.abao;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.pili.pldroid.playerdemo.R;
public class ClassexitActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_classexit);
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_classexit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.xdy.abao.ClassexitActivity">
</RelativeLayout>
... ...
... ... @@ -170,6 +170,8 @@ public interface Constants {
* 获取Audio推流地址
*/
String GET_AUDIO_PUBLISH_PATH="getAudioPublishPath";
String UN_PUBLISH_VIDEO="unPublishVideo";
/*Context为空的时候给出的提示*/
String ERROR_CONTENT_NULL="Xdy,init context is null";
/*判断XdyCore是否被初始化*/
... ... @@ -194,4 +196,9 @@ public interface Constants {
* 推流成功
*/
String PUBLISH_RERUEN_SUCCESS="publishSuccess";
/**
* 播放音视频,出现画面, 同时返回id
*/
String PLAY_SUCCESS="play_success";
}
... ...
... ... @@ -8,6 +8,9 @@ public class APIContants {
/*与js调用设置的常量*/
protected final static String NATIVE_JS_LINK="xdyAndroid";
/*baseUrl*/
// protected final static String BASE_URL="http://192.168.1.118/xdysdk/web/";
// protected final static String BASE_URL="http://192.168.1.109/xdysdk/web/";
protected final static String BASE_URL="http://h5.test.3mang.com/web/";
}
... ...
... ... @@ -6,6 +6,7 @@ package com.mang.xdy.core;
import android.content.Context;
import android.os.Build;
import android.text.NoCopySpan;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
... ... @@ -24,7 +25,6 @@ public class XdyJsCore {
private WebView mWebView;
private static String TAG="xdyjscore";
private static XdyJsCore mXdyCore;
protected boolean isDestroy=false;
private XdyJavaScript mXdyJavaScript;
/**
* 异步对外回调接口,所有回调都在此完成
... ... @@ -46,20 +46,20 @@ public class XdyJsCore {
}
init(context);
}
/**
* 初始化
* @param context
*/
protected void init(Context context){
if(context==null){
return;
}
//清理Webview缓存数据库
mXdyJavaScript=new XdyJavaScript();
mWebView=new WebView(context);
WebSettings webSettings=mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.getSettings().setAppCacheEnabled(false);
webSettings. setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存
mXdyJavaScript=new XdyJavaScript();
webSettings.setAppCacheEnabled(false);
mWebView.addJavascriptInterface(mXdyJavaScript, APIContants.NATIVE_JS_LINK);
mWebView.setWebChromeClient(new WebChromeClient(){
@Override
... ... @@ -76,7 +76,12 @@ public class XdyJsCore {
}
});
}
@Deprecated
public void reSetXdyJavaScript(){
mXdyJavaScript=new XdyJavaScript();
mWebView.removeJavascriptInterface(APIContants.NATIVE_JS_LINK);
mWebView.addJavascriptInterface(mXdyJavaScript, APIContants.NATIVE_JS_LINK);
}
/**
* 获取XdyCore实例
* @param context
... ... @@ -113,42 +118,17 @@ public class XdyJsCore {
* @param parameter
*/
protected void native2js( String id, String parameter) {
XdyLogUtil.e("推流线程native2js:",Thread.currentThread().getId()+"");
XdyLogUtil.e("推流线程native2js:",Thread.currentThread().getId()+"id:"+id);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("javascript:_native2js('" + id + "','"+parameter+"')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
XdyLogUtil.e(TAG+"同步获取的数据", value);
//TODO
// if (!TextUtils.isEmpty(value)&&value.length()>10) {
// if(mOnXdyAsyncMessageListener !=null){
// mOnXdyAsyncMessageListener.getSdyAsyncMessageListener("live",value);
// }
// }
// if (!TextUtils.isEmpty(value)&&value.length()>10) {
// if(mOnXdyAsyncMessageListener !=null){
// mOnXdyAsyncMessageListener.getSdyAsyncMessageListener(id,value);
// }
// }
}
});
}else{
mWebView.loadUrl("javascript:_native2js('" + id + "','"+parameter+"')");
}
}
/**
* 清除缓存
*/
public void onDestroy(){
if(mWebView!=null){
mWebView.clearHistory();
}
if(mXdyJavaScript!=null){
mXdyJavaScript=null;
}
mXdyJavaScript= new XdyJavaScript();
}
}
... ...
... ... @@ -46,6 +46,7 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
protected int video_opt = 1;
int videoWidth = 640;
private int videoHight = 480;
/*是否推流的标志,true 开始推送,false不推送*/
private boolean isStart = false;
/*是否支持硬编码 默认不支持*/
private boolean is_hardware_encoder = false;
... ... @@ -191,8 +192,10 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
private void initCamera(SurfaceHolder holder) {
Log.i(TAG, "initCamera..");
if (mPreviewRunning)
if (mPreviewRunning) {
if(mCamera!=null)
mCamera.stopPreview();
}
Camera.Parameters parameters;
try {
... ... @@ -429,6 +432,24 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
isStart=false;
}
/**
* onPause 方法调用,不释放相机资源
*/
protected void onPausePublisher(){
isStart=false;
if (audioRecord_ != null) {
XdyLogUtil.i(TAG, "surfaceDestroyed, call StopRecording..");
audioRecord_.StopRecording();
audioRecord_ = null;
}
if (xdyPublisher != null) {
xdyPublisher.SmartPublisherStop();
}
}
public void onResumePublisher(){
isStart=true;
}
private int setHardwareEncoderKbps(int width, int height)
{
int hwEncoderKpbs = 0;
... ...
... ... @@ -42,7 +42,7 @@ public class XdySdk implements SubjectListener{
/**
* 用户初始化,还是调用各种方法,都需要统一的对外给出监听事件
*/
private static XdyJsCore mXdyJsCore;
private static XdyJsCore mXdyJsCore;
private static XdySdk mXdySdk;
private static Context mContext;
private XdyPlayerCore mXdyPlayerCore;
... ... @@ -59,6 +59,8 @@ public class XdySdk implements SubjectListener{
private Activity mActivity;
/*是否正在推流,mcu自动断开的时候使用,推流成功后才表示正在使用*/
private boolean isPublisher=false;
/*推流重连状态,如果是重连状态会有一系列加入课堂的情况*/
private boolean isReconnection=false;
/*观察者集合*/
private List<ObserverListener> observerListenerList=new ArrayList<ObserverListener>();
... ... @@ -82,13 +84,13 @@ public class XdySdk implements SubjectListener{
}
/**
* 清除信息
* 退出时清除信息(重置js监听)
*/
public void removeAll(){
// if(observerListenerList!=null){
// observerListenerList.clear();
// }
mXdyJsCore.onDestroy();
// mXdyJsCore.init(mContext);
}
/**
... ... @@ -169,21 +171,18 @@ public class XdySdk implements SubjectListener{
judgeCore();
//再次停止播放器
switch (type){
case "unPublishAudio":
//停止推送音频
case "unPublishVideo":
//停止推流video(关闭视频:根据api)
onPublisherStop();
break;
// case "unPublishAudio":
// //停止推送音频
// case "unPublishVideo":
// //停止推流video(关闭视频:根据api)
// onPublisherStop();
// break;
case "stopAudio":
//停止播放audio()
case"stopVideo":
//停止播放video( 停止播放:根据api)
// onPlayStop();
break;
case "init":
mXdyJsCore.isDestroy=false;
break;
}
handler.post(new Runnable() {
@Override
... ... @@ -332,6 +331,7 @@ public class XdySdk implements SubjectListener{
// String publishPath=XdyStringUtils.stringToJson(response);
String publishPath=response;
GetPublishPathReceiveBean getPublishPathReceiveBean=JsonUtil.parseJsonToBean(publishPath,GetPublishPathReceiveBean.class);
if(getPublishPathReceiveBean!=null) {
//可以推流了
if (getPublishPathReceiveBean.getCode() == 0) {
... ... @@ -350,6 +350,8 @@ public class XdySdk implements SubjectListener{
if (mXdyPublisherCore == null) {
mXdyPublisherCore = new XdyPublisherCore(1, 1, mActivity);
}
publish_url=video_url;
isPublisher=true;
mXdyPublisherCore.publisher(video_url,mSurfaceView, new EventHande());
// PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH));
//// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断)
... ... @@ -386,6 +388,7 @@ public class XdySdk implements SubjectListener{
if(mXdyPublisherCore==null)
mXdyPublisherCore=new XdyPublisherCore(1,0,mActivity);
mXdyPublisherCore.publisherAudio(audio_url,new EventHande());
isPublisher=true;
//// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断)
PlayerUtils.setPublishSendSuccessAudio(audio_url);
}else{
... ... @@ -402,7 +405,7 @@ public class XdySdk implements SubjectListener{
if(publisherVideoReturnBean_audio!=null&&publisherVideoReturnBean_audio.getCode()==0){
XdyLogUtil.e(TAG,"后台成功接收到,推流的地址");
//TODO
isPublisher=true;
handleListener(Constants.PUBLISH_RERUEN_SUCCESS,"");
}else{
//TODO
... ... @@ -447,18 +450,49 @@ public class XdySdk implements SubjectListener{
if(errorCodeEntity!=null){
if(errorCodeEntity.getCode()==Constants.LEAVE_CLASS_CODE){
/**
* 正在直播的时候mcu无故断开,需要重新连接
* 方案 一 1,正在直播的时候mcu无故断开,需要重新连接
* 2,class exit 时候主动课堂停止,停止推流
* 利用mcu的生命周期,加入课堂成功后去请求数据
*/
//mcu 断开,页面也断开,用户需要重新调用
// if(isPublisher) {
// 方案 二 mcu 断开,页面也断开,用户需要手动重新调用
if(isPublisher) {
// onPublisherStop();
// api("publishVideo", "", mSurfaceView, mActivity);
// }
onPublisherStop();
isReconnection=true;
// XdyLogUtil.e("mcu 断线了重连","断线重连,使用的都是同一个保存的url");
// api(Constants.UN_PUBLISH_VIDEO,"");
// setPublishSendSuccessVideo(publish_url);
// getPublishPathVideo();
}
// onPublisherStop();
}
}
handleListener(type,response);
break;
case Constants.CLASS_EXIT:
/**
* 处理正在推流视频,课堂退出的情况,(用户操作退出界面)
* 此时,停止推流,清除surfaceview Activtity 数据,url数据
*/
if(isPublisher){
onPublisherStop();
}
handleListener(type,response);
break;
case Constants.CLASS_JOIN_SUCCESS:
if(isReconnection){
// api("stopPublishVideo","");
// if(mXdyPublisherCore!=null){
// mXdyPublisherCore.onStopPublisher();
// mXdyPublisherCore=null;
// }
// getPublishPathVideo();;
// setPublishSendSuccessVideo(publish_url);
}
handleListener(type,response);
break;
default:{
handleListener(type,response);
}
... ... @@ -491,11 +525,23 @@ public class XdySdk implements SubjectListener{
if (mXdyPlayerCore != null) {
mXdyPlayerCore.onStopPlay();
// mXdyPlayerCore = null;
}
return true;
}
return false;
}
/**
* onPause 暂停所有的,退出都在这里
*/
public void onPlayPauseAll(){
if(mXdyPlayerCore!=null) {
mXdyPlayerCore.onPause();
}
if(mXdyJsCore!=null) {
mXdyJsCore.init(mContext);
}
}
/**
* 结束时调用
... ... @@ -526,42 +572,65 @@ public class XdySdk implements SubjectListener{
mActivity = null;
}
}
// isPublisher=false;
isPublisher=false;
isReconnection=false;
}
/**
* onPause 方法时走的周期
*/
public void onPublisherPause(){
if(mXdyPublisherCore!=null){
mXdyPublisherCore.onPausePublisher();
}
}
private String publish_url="";
/**
* onResume 调用,目前是空方法
* TODO 只有一个boolean
*/
public void onPublisherResume(){
if(mXdyPublisherCore!=null) {
mXdyPublisherCore.onResumePublisher();
if (!TextUtils.isEmpty(publish_url)) {
mXdyPublisherCore.publisher(publish_url, mSurfaceView, new EventHande());
}
}
}
class EventHande implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
Log.e(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
Log.e(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
Log.e(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
Log.e(TAG, "连接成功。。");
//TODO //如果连接成功发送连接成功信息,判断的方式有待考虑
// PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH));
// XdySdk.getXdyInstance().notifyObserver("video_success","");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
Log.e(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
notifyObserver("play_stop",currentPlayId+"");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
Log.e(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
//在这里最接近得到播放的成功的准确回调
notifyObserver("video_success",currentPlayId+"");
notifyObserver(Constants.PLAY_SUCCESS,currentPlayId+"");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
Log.e(TAG, "收不到媒体数据,可能是url错误。。");
}
}
... ...
... ... @@ -6,9 +6,8 @@ import com.mang.xdy.bean.ErrorCodeEntity;
/**
* Created by abao on 2017/4/13.
* 对外返回错误信息
*
*@deprecated
*/
public class MsgManage {
private MsgManage(){}
private static class ErrorInner{
... ...
package com.mang.xdy.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* 网络工具类
*/
public class NetWorkUtils {
private NetWorkUtils(){
/* cannot be instantiated */
throw new UnsupportedOperationException("cannot be instantiated");
}
/**
* 判断是否有网络连接
* @param context
* @return
*/
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
/**
* 判断WIFI网络是否可用
* @param context
* @return
*/
public static boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWiFiNetworkInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWiFiNetworkInfo != null) {
return mWiFiNetworkInfo.isAvailable();
}
}
return false;
}
/**
* 判断MOBILE网络是否可用
* @param context
* @return
*/
public static boolean isMobileConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mMobileNetworkInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mMobileNetworkInfo != null) {
return mMobileNetworkInfo.isAvailable();
}
}
return false;
}
/**
* 获取当前网络连接的类型信息
* @param context
* @return
*/
public static int getConnectedType(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
return mNetworkInfo.getType();
}
}
return -1;
}
/**
* 获取当前的网络状态 :没有网络0:WIFI网络1:3G网络2:2G网络3
*
* @param context
* @return
*/
public static int getAPNType(Context context) {
int netType = 0;
ConnectivityManager connMgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_WIFI) {
netType = 1;// wifi
} else if (nType == ConnectivityManager.TYPE_MOBILE) {
int nSubType = networkInfo.getSubtype();
TelephonyManager mTelephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
&& !mTelephony.isNetworkRoaming()) {
netType = 2;// 3G
} else {
netType = 3;// 2G
}
}
return netType;
}
}
\ No newline at end of file
... ...
This file is too large to display.
This file is too large to display.
This file is too large to display.