洛米对接文档

1.API接入指南

1-1 API申请步骤

步骤1:在[洛米官网](http://www.luomi.com)中注册成为开发者

步骤2:创建一款应用,您将获得一个appkey,用于标识您的应用

步骤3:联系客服人员审批应用

步骤4:获取相应API的接口

2-2 获取广告API对接说明

API对接说明文档地址

2.安卓SDK接入指南

点击下载sdk对接文档

3.IOS-SDK接入指南

点击下载sdk对接文档

4.API对接下载必看

由于本平台有Https的广告链接,所有开发者实现的webview需要支持https的处理,否则可能影响计费:下面给出具体代码,如若还有问题请及时沟通

分析:在Android5.0以下,默认是采用的MIXED_CONTENT_ALWAYS_ALLOW模式,即总是允许WebView同时加载Https和Http;而从Android5.0开始,默认用MIXED_CONTENT_NEVER_ALLOW模式,即总是不允许WebView同时加载Https和Http


1、 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {  
       webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);  
    } 

3、下载方式
	mWebView.setDownloadListener(new DownloadListener() {
		@Override
		public void onDownloadStart(final String url, String userAgent,
			String contentDisposition, String mimetype,
			long contentLength) {
			String content = "是否确定下载该游戏?";
			content = "当前是非WIFI状态,是否继续下载?";
			AlertDialog.Builder builder = new AlertDialog.Builder(
			context);
				builder.setTitle("下载提示")
					.setMessage(content)
					.setPositiveButton("确定",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(
							DialogInterface dialog,
							int which) {
								//方式1   跳转浏览器下载
								Intent intent= new Intent();        
								intent.setAction("android.intent.action.VIEW");    
								Uri content_url = Uri.parse(url);   
								intent.setData(content_url);  
								startActivity(intent);
								//方式2  用安卓原生的DownLoadmanager下载   具体参考第6项
								//方式3  自行实现下载逻辑
							}
						})
						.setNegativeButton("取消",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(
									DialogInterface dialog,
									int which) {

								}
						});
				dialog = builder.create();
				if (context.hasWindowFocus()) {
					dialog.show();
				}
			}

	});

4、由于广告链接涉及到下载功能,如果开发者的targetSDK>=23需要动态申请文件读写权限,另外安装时加入targetSDK>=25需要加权限
	<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

5、安卓7.0版本适配安装
<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="包名.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">

            <!-- 元数据 -->
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"/>
    </provider>

6、DownloadManager下载伪代码
public class MainActivity extends AppCompatActivity {
		private DownloadUtils downloadUtils;
		@Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_main);
			downloadUtils =   new DownloadUtils(MainActivity.this); 
			downloadUtils.downloadAPK("http://XXX.apk", "XXX.apk");

    }
	
	public class DownloadUtils {
    //下载器
    private DownloadManager downloadManager;
    //上下文
    private Context mContext;
    //下载的ID
    private long downloadId;
    public  DownloadUtils(Context context){
        this.mContext = context;
    }

    //下载apk
    public void downloadAPK(String url, String name) {

        //创建下载任务
        Request request = new Request(Uri.parse(url));
        //移动网络情况下是否允许漫游
        request.setAllowedOverRoaming(false);

        //在通知栏中显示,默认就是显示的
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
        request.setTitle("新版本Apk");
        request.setDescription("Apk Downloading");
        request.setVisibleInDownloadsUi(true);

        //设置下载的路径
        request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().getAbsolutePath() , name);

       //获取DownloadManager
        downloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
        //将下载请求加入下载队列,加入下载队列后会给该任务返回一个long型的id,通过该id可以取消任务,重启任务、获取下载的文件等等
        downloadId = downloadManager.enqueue(request);

        //注册广播接收者,监听下载状态
        mContext.registerReceiver(receiver,
                new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    }

    //广播监听下载的各个状态
    private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            checkStatus();
        }
    };


    //检查下载状态
    private void checkStatus() {
        Query query = new Query();
        //通过下载的id查找
        query.setFilterById(downloadId);
        Cursor c = downloadManager.query(query);
        if (c.moveToFirst()) {
            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
            switch (status) {
                 //下载暂停
                case DownloadManager.STATUS_PAUSED:
                    break;
                //下载延迟
                case DownloadManager.STATUS_PENDING:
                    break;
                //正在下载
                case DownloadManager.STATUS_RUNNING:
                    break;
                //下载完成
                case DownloadManager.STATUS_SUCCESSFUL:
                    //下载完成安装APK
                    installAPK();
                    break;
                //下载失败
                case DownloadManager.STATUS_FAILED:
                    Toast.makeText(mContext, "下载失败", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
        c.close();
    }

    //下载到本地后执行安装
    private void installAPK() {
        //获取下载文件的Uri
        Uri downloadFileUri = downloadManager.getUriForDownloadedFile(downloadId);
        if (downloadFileUri != null) {
            Intent intent= new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(downloadFileUri, "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
            mContext.unregisterReceiver(receiver);
        }
    }

}
}