主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);//全局初始化此配置 } }
时间: 2024-10-15 18:12:41