- android studio 无法连接魅族手机
解决方法:先下载小数据包 http://download.youkuaiyun.com/detail/lazyman1989/8858467,解压得到adb_usb.ini文件,在Mac下将这个文件拖到/Users/myaccount/.android文件夹执行替换并重启android studio即可。
由于.android是系统文件夹,在一般情况下不可见,通过如下两条指令快速使其可见(或否)。
显示:defaults write com.apple.finder AppleShowAllFiles -bool true
隐藏:defaults write com.apple.finder AppleShowAllFiles -bool false
Done。
- 试图打开Android手机上的市场应用,app崩溃。
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
以上代码在手机上没有市场应用时会报ActivityNotFoundExcejption。犯了低级错误,更改如下:
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if( intent.resolveActivity(getPackageManager()) != null ) {
startActivity(intent);
}else {
ToastUtil.show(this, "提示用户未安装市场应用", Toast.LENGTH_LONG);
}
Done。
- 用ShareSDK分享图片到QQ,崩溃。
platForm = ShareSDK.getPlatform(QQ.NAME);
ShareParams params = new ShareParams();
...
params.setText(desc);
经查,是desc为空字符串(不是null)的缘故。
QQ,QZone分享常见问题 http://bbs.mob.com/forum.php?mod=viewthread&tid=41&page=1&extra=#pid57
- 用ShareSDK分享图片到QQ,在pc上显示为null。
用ShareSDK来分享图片到QQ,效果不好,因为在PC上看到的null,而且setText后,这些描述性文字会跟要分享的图片被混合在一张图片上了,感觉很奇怪。如果调用系统的分享功能,然后在弹出的Dialog中选择QQ,分享的效果就跟向某位好友发送图片一样,有时候这个才是想要的。
Uri uri = Uri.fromFile(destFile);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jgp");
i.putExtra(Intent.EXTRA_STREAM,uri);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if( intent.resolveActivity(getPackageManager()) != null ) {
startActivity(Intent.createChooser(i,"分享图片"));
}else {
ToastUtil.show(this, "提示sth", Toast.LENGTH_LONG);
}
这个方法中间会弹Dialog,让用户选择应用。想直接分享到QQ,又不失效果,可以用这个小技巧:
try{
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jgp");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setClassName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
context.startActivity(Intent.createChooser(i,"分享图片"));
//提示用户分享成功
}catch(Exception e) {
//提示用户分享失败,log
}
这个关键点就是要知道QQ的包名和响应的Activity,寻找这两个东西的关键词Logcat,PackageManager。其它app同理可得。
Done。
- TextView setTextColor无效
tv.setTextColor(getResources().getColor(R.color.selector_normal));
发现这个color是Selector,所以修改为
tv.setTextColor(getResources().getColorStateList(R.color.selector_normal));
ok now。
res/color / xxx_selector.xml 不能用于TextView background(报错),可以用于textColor。
Done。
- android 4.0以上用 shape 画虚线,展示的是实线。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp" android:color="#d5d5d5"
android:dashWidth="3dp" android:dashGap="5dp" />
</shape>
解决方法:
<View
android:id="@+id/dash"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_alignParentBottom="true"
android:background="?attr/dash_line"
android:layerType="software"
/>
在xml里加android:layerType=”software”,关闭硬件加速。或者调用View.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Done.