1. 程式人生 > >第三方登錄之qq

第三方登錄之qq

pools 定義 button context edm set init () div

主MainActivity

public class MainActivity extends AppCompatActivity {

    private Button btn;
    private TextView tv;
    private ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn 
= (Button) findViewById(R.id.btn); tv = (TextView) findViewById(R.id.tv); image = (ImageView) findViewById(R.id.image); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { UMShareAPI.get(MainActivity.this
).getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, umAuthListener); } }); } private UMAuthListener umAuthListener = new UMAuthListener() { @Override public void onStart(SHARE_MEDIA platform) { //授權開始的回調 } @Override public
void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) { Toast.makeText(getApplicationContext(), "Authorize succeed", Toast.LENGTH_SHORT).show(); String name = data.get("name"); String gender = data.get("gender"); String photoUrl = data.get("iconurl"); tv.setText(name + " " +gender); ImageLoader.getInstance().displayImage(photoUrl,image); } @Override public void onError(SHARE_MEDIA platform, int action, Throwable t) { Toast.makeText( getApplicationContext(), "Authorize fail", Toast.LENGTH_SHORT).show(); } @Override public void onCancel(SHARE_MEDIA platform, int action) { Toast.makeText( getApplicationContext(), "Authorize cancel", Toast.LENGTH_SHORT).show(); } }; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); } }

Appliction

public class appliction extends Application{
    private static appliction mAppApplication;

    //第三 加權限 第四功能清單加activity 第五功能清單加meta 第六加下面這行代碼
    {
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
    }

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        initImageLoader(getApplicationContext());
        mAppApplication = this;

        //第七 初始化   ,第八加簽名文件 ,第九 在gradle裏面配置簽名文件
        UMShareAPI.get(this);
    }

    /**
     * 獲取Application
     */
    public static appliction getApp() {
        return mAppApplication;
    }


    /** 初始化ImageLoader */
    /**
     * 初始化ImageLoader
     */
    public static void initImageLoader(Context context) {
        File cacheDir = StorageUtils.getOwnCacheDirectory(context, "topnews/Cache");//獲取到緩存的目錄地址
        Log.d("cacheDir", cacheDir.getPath());
        //創建配置ImageLoader(所有的選項都是可選的,只使用那些你真的想定制),這個可以設定在APPLACATION裏面,設置為全局的配置參數
        ImageLoaderConfiguration config = new ImageLoaderConfiguration
                .Builder(context)
                .threadPoolSize(3)//線程池內加載的數量
                .denyCacheImageMultipleSizesInMemory()//.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation你可以通過自己的內存緩存實現
                .memoryCacheSize(2 * 1024 * 1024)
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())//將保存的時候的URI名稱用MD5 加密
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .diskCache(new UnlimitedDiskCache(cacheDir))
                //自定義緩存路徑//.imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超時時間
                .build();
        ImageLoader.getInstance().init(config);//全局初始化此配置
    }

 }

第三方登錄之qq