打开您项目的“AndroidManifest.xml”,在其中添加如下的权限:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
然后在“application”下添加如下activity:
<activity android:name="com.mob.tools.MobUIShell" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|screenSize" android:windowSoftInputMode="stateHidden|adjustResize"/> //
//填写申请的APPkey和Appsecret SMSSDK.initSDK(this,"1c0fac923df8e","c536778d4c4b05bcb3d21faa396b02c1"); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //打开注册界面 RegisterPage registerPage=new RegisterPage(); registerPage.setRegisterCallback(new EventHandler(){ @Override //短信sdk操作回调 public void afterEvent(int i, int i1, Object o) { super.afterEvent(i, i1, o); //解析注册结果 if(i1==SMSSDK.RESULT_COMPLETE){//如果状态为完成状态,表示成功注册 //获得Data的值 HashMap<String,Object>datamaps=(HashMap<String, Object>)o; //获取手机所在的国家 String country = (String) datamaps.get("country"); //获取收到验证码的手机号码 String phone = (String) datamaps.get("phone"); //提交信息到mob注册 SubmitInfo(country,phone); } } }); registerPage.show(MainActivity.this); } }); } private void SubmitInfo(String country,String phone) { Random r=new Random(); String uid=Math.abs(r.nextInt())+""; String name="设置昵称"; //提交用户信息,在监听中返回 SMSSDK.submitUserInfo(uid,name,null,country,phone); }