編輯:關於Android編程
先借助Android studio工具新建一個新的空項目。
步驟一(獲取appkey)
1.在極光官網平台上新建短信應用(根據要求包名和應用名稱填寫好)
2.獲取得到Jpush_AppKey
步驟二 (導入第三方庫和so文件)
1.用Android studio打開應用
2.切換應用狀態Android為Project狀態
3.在libs文件夾下把對應的jar文件拷入 然後as libraries
步驟三(初始化以及調用)
1.新建Application初始化
public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); SMSSDK.getInstance().setDebugMode(true); SMSSDK.getInstance().initSdk(this); } }
2.在activity中調用
public class MainActivity extends BaseActivity { EditText edit_name; EditText edit_pwd; EditText sms; String name; String pwd; Button get_sms; Button btn_login; private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 1: Toast.makeText(MainActivity.this, msg.obj.toString(), Toast.LENGTH_SHORT).show(); break; case 2: Toast.makeText(MainActivity.this, msg.obj.toString(), Toast.LENGTH_SHORT).show(); break; case 3: Toast.makeText(MainActivity.this, msg.obj.toString(), Toast.LENGTH_SHORT).show(); break; case 4: Toast.makeText(MainActivity.this, msg.obj.toString(), Toast.LENGTH_SHORT).show(); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } private void init() { edit_name = (EditText) findViewById(R.id.edit_name); edit_pwd = (EditText) findViewById(R.id.edit_pwd); sms = (EditText) findViewById(R.id.sms); get_sms = (Button) findViewById(R.id.get_sms); btn_login = (Button) findViewById(R.id.btn_login); get_sms.setOnClickListener(new GetSmsClickListener()); btn_login.setOnClickListener(new LoginClickListener()); } public class GetSmsClickListener implements View.OnClickListener { @Override public void onClick(View view) { name = edit_name.getText().toString().trim(); pwd = edit_pwd.getText().toString().trim(); if (name.equals("")) { edit_name.requestFocus(); } else if (pwd.equals("")) { edit_pwd.requestFocus(); } else { new Thread(new Runnable() { @Override public void run() { try { GetSmsCode(name, pwd); } catch (Exception ex) { ex.printStackTrace(); } } }).start(); } } } private void GetSmsCode(String name, String pwd) { GetCode(this.name, this.pwd, new GetCodeListener() { @Override public void getCodeSuccess(String s) { Message msg = Message.obtain(); msg.obj = s; msg.what = 1; handler.sendMessage(msg); } @Override public void getCodeFail(String s) { Message msg = Message.obtain(); msg.obj = s; msg.what = 2; handler.sendMessage(msg); } }); } public class LoginClickListener implements View.OnClickListener { @Override public void onClick(View view) { final String code = sms.getText().toString().trim(); name = edit_name.getText().toString().trim(); pwd = edit_pwd.getText().toString().trim(); if (name.equals("")) { edit_name.requestFocus(); } else if (pwd.equals("")) { edit_pwd.requestFocus(); } else if (code.equals("")) { sms.requestFocus(); } else { new Thread(new Runnable() { @Override public void run() { try { CheckSmsCode(name, pwd, code); } catch (Exception ex) { ex.printStackTrace(); } } }).start(); } } } private void CheckSmsCode(String name, String pwd, String code) { CheckCode(this.name, this.pwd, code, new CheckCodeListener() { @Override public void checkCodeSuccess(String s) { Message msg = Message.obtain(); msg.obj = s; msg.what = 3; handler.sendMessage(msg); } @Override public void checkCodeFail(String s) { Message msg = Message.obtain(); msg.obj = s; msg.what = 4; handler.sendMessage(msg); } }); } }
步驟四(填寫配置文件)
1.配置應用權限
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
2.配置meta (appkey 從平台上新建的對應應用中來)
<meta-data android:name="JPUSH_APPKEY" android:value="You JPUSH_APPKEY"/>
步驟五(調試)
1.點擊獲取密碼按鈕獲取短信信息
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持本站。
今天和大家聊一聊Android中關於FontMetrics的幾個屬性的理解,在Android中用畫筆繪制文字時,文字最終的大小是和繪制文字的字體的類型和字體的大小是相關的
學習到的知識整個事件流向應該是從Activity—->ViewGroup—>View 從上往下調用dispatchTouchEvent
IOS現成的API裡的json解析速度非常快,這裡就不說了,今天對比一下Android裡面json的解析庫。首先第一個是Android API裡面自帶的json解析,其次
最近公司項目需要,要做一個自己的IMSDK,順便先把之前沒有記錄的群聊功能記錄一下。先上資料,查看XMPP群聊相關的資料,可以去這裡看協議:XEP-0045 。創建群組X