我想使用Proguard主要是出于混淆的原因.
我的问题是我有三个库,Twitter4J和两个路标库.当我尝试创建签名的APK时,这些库会导致错误.为了克服这个问题,我在proguard.config文件中添加了以下内容......
-dontwarn org.apache.commons.codec.binary.**
-dontwarn org.slf4j.**
-dontwarn com.sun.syndication.io.**
-dontwarn com.sun.syndication.feed.synd.*
Run Code Online (Sandbox Code Playgroud)
虽然这摆脱了控制台中的错误,当我将签名的APK加载到我的手机上时,它立即崩溃了.DDMS说这是由于Twitter4J中没有找到的课程.
摆脱"dontwarns"上述情况并没有帮助.也没有添加dontshrink dontoptimise.
我希望Proguard完全忽略这些库(因为它们无论如何都是开源的).这可能吗?
我有一个EditText对话框.EditText在创建时已经填充.当用户将光标放在文本的某些部分上或附近时,将弹出Toast.
我的问题是监听光标位置的变化.另一篇文章提出了同样的问题,并且接受的解决方案是
您可以覆盖onSelectionChanged(int selStart,int selEnd)以获得有关选择更改的通知.如果移动光标,也会调用它(在本例中为selStart == selEnd)
onSelectionChanged(int selStart,int selEnd)是TextView类的受保护方法.如何覆盖它?
解决方案对我 有用...嗨大师,谢谢你的回复,它的工作原理.如果其他人有兴趣,这就是我做的详细...
第一步:创建子类
__PRE__
第二步:引用布局文件中的类(例如main.xml(尽管我的是自定义对话框布局)).不要忘记使用完整的包名(在本例中为com.example.EditTextCursorWatcher,例如
__PRE__
我有一个主要活动,用户可以将背景颜色(通过偏好)更改为他们喜欢的颜色.我的问题是我无法更改任何自定义对话框的背景颜色.
堆栈溢出的其他答案建议:
(a)将默认主题覆盖为首选颜色.我不认为在这种情况下是一个合适的解决方案,因为我知道不建议在运行时更改主题.
(b)在styles.xml中更改(在这种情况下不适合,因为我无法在运行时更改)
(c)覆盖AlertBuilder类(但这会使整个警报对话框着色)
我最近改变颜色的方法是删除警报构建器标题,并将自定义视图的背景设置为喜欢的颜色(例如,粉红色).不幸的是,这会在对话框的顶部和底部产生一个丑陋的条带.
代码包含在图像之后,有关如何更改对话框背景的建议将不胜感激.

默认外观的代码
protected Dialog onCreateDialog(int dialogId) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final View viewMessEdit = inflater.inflate(R.layout.example,(ViewGroup) findViewById(R.id.dialog_mess_edit_root));
builder.setView(viewMessEdit);
builder.setTitle("Alert builder's title");
}
Run Code Online (Sandbox Code Playgroud)
用于更改自定义对话框视图背景颜色的代码(并删除了"警报"构建器的标题)
protected Dialog onCreateDialog(int dialogId) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final View viewMessEdit = inflater.inflate(R.layout.example,(ViewGroup) findViewById(R.id.dialog_mess_edit_root));
builder.setView(viewMessEdit);
viewMessEdit.setBackgroundResource(R.color.pink_dark);
}
Run Code Online (Sandbox Code Playgroud) 我在Google Play市场上有一款应用.由于各种原因,我不打算进入,我已经改变了我的一些偏好的类型.例如,首选项类型是Integer,在最新版本中它现在是String.我想这不是一个好习惯,但不幸的是我不得不这样做.
我担心的是,当有人更新新版本时,他们的应用会因偏好类型发生变化而崩溃.出于这个原因,我想在应用程序更新时清除首选项(再次,我意识到不理想!)
这可能吗?
我有一个我在服务中动态创建的BroadcastReceiver.其目的是检测何时发送SMS.它按预期工作.
我的麻烦是我收到一条错误,说"意图接收器已泄露".我错过了一个电话unregisterReceiver()吗?
我正在调用unregisterReceiver()在onDestroy().我想这一定是错的.我应该在哪里取消注册接收器?
码...
public class MyService extends Service {
BroadcastReceiver brSms;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
}
@Override
public void onStart(Intent intent, int startid) {
//Define the receiver
brSms = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Do some stuff
};
}
registerReceiver(brSms, new IntentFilter(SENT_SMS_ACTION));
}
@Override
public void onDestroy() {
unregisterReceiver(brSms);
Toast.makeText(this, "onDestroy has been called", Toast.LENGTH_SHORT).show();
}
}//end …Run Code Online (Sandbox Code Playgroud) 我认为这可能会影响很多Facebook/Android开发者,但似乎没有那么多讨论这个话题......
我的问题
有没有人使用extendAccessTokenIfNeeded函数成功刷新令牌?如果确实有成功,那么设备(或仿真器)的运行版本是什么?
背景
我收到了来自Facebook的电子邮件,称从2012年5月1日起将弃用offline_access权限,Facebook建议升级到最新的SDK.精细.
我升级到最新的SDK,官方Facebook应用程序安装在我的设备上(最终!)单点登录似乎工作正常.我收到了60天的代币,再次没问题.
当我尝试使用extendAccessTokenIfNeeded(Context context,ServiceListener serviceListener)时出现问题.我无法让它刷新我的令牌更长的到期时间.我在尝试之间等了24小时,但令牌不会刷新.我可以获得刷新令牌的唯一方法是注销并登录.当我使用示例项目"Hackbook"时也会发生这种情况.
最明显的答案是我做错了什么,但是,一个错误报告被提交给Facebook说......"shouldExtendAccessToken实际上几乎总是会返回错误." 该报告已被列为优先"愿望清单".
extendAccessTokenAsNeeded()的替代方案
在关于offline_access的Facebook文档中,可以使用Graph API扩展弃用令牌.然而,这具有需要将"App Secret"包括在URL中的缺点.优点是用户不需要在他们的设备上安装官方Facebook应用程序.
其他想法和顾虑
通过将Facebook.java中的extendAccessTokenIfNeeded函数更改为始终返回true,我想我已经刷新了一次.(我说"思考"的原因是因为它不会重复这种行为,我怀疑我必须再等24小时才能再次成功)
我注意到Hackbook需要导入AndroidHttpClient.这仅适用于API 8及更高版本.这是否意味着Facebook SSO(特别是令牌刷新)只能在API 8及更高版本的设备上运行?
SDK中包含的Facebook.apk已经很老了.也许这就是为什么令牌不会在运行API 8及更高版本的模拟器上刷新的原因?
最后,所有这些只与那些安装了官方Facebook应用程序的人有关!对于那些没有官方Facebook应用程序的人来说,需要完成另一种方法(现在就抱怨!)
相关的Facebook链接
相关的Stack Overflow问题
我和这篇文章有完全相同的问题.我希望我的自定义通知文本样式与默认通知匹配(我只是添加一些额外的视图).不幸的是,我不完全理解接受的答案.我想我应该添加到XML代码但不确定究竟是什么......

接受的答案是"解决方案是使用内置样式.你需要的样式是TextAppearance.StatusBar.EventContent.只需应用这个样式,它将设置通知的默认文本颜色(不要忘记android:前缀,当然)."
我不能让这个工作!在我的自定义通知下面的行"android:textAppearance ="?android:attr/textAppearanceLarge"工作(因为它扩大了文本),但没有给出所需的效果.
这是我的自定义XML代码......
<ImageView
android:id="@+id/notImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/notContentTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf ="@id/notImage"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/notContentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below ="@id/notContentTitle"
/>
Run Code Online (Sandbox Code Playgroud)
我已经看到很多关于如何在用户点击通知时发生某些事情但我实际上不希望发生任何事情的例子.如果用户点击通知,我希望通知只是消失,用户不会被带到任何地方.
在下面的代码中,当FLAG_AUTO_CANCEL清除状态栏中的通知时,当用户点击我的通知时,他们将被带到"MyActivity".
如何创建无效的通知?
Notification notification = new Notification(R.drawable.success, res.getString(R.string.messages_sent), System.currentTimeMillis());
//Define the expanded message and intent
Context context = getApplicationContext();
CharSequence contentTitle = res.getString(R.string.messages_sent_ellipsis);
Intent notificationIntent = new Intent(this, MyActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0 );
notification.setLatestEventInfo(context, contentTitle, mStrSuccessMessage, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//Pass the notification to the notification manager
mNotificationManager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码创建自定义首选项.xml布局文件有一个Button,EditText和TextView.此自定义布局显示在Alert"确定"和"取消"按钮内.这一切都运作良好.
我想在"确定"和"取消"按钮旁边添加第三个按钮(中性按钮).我已经对该AlertBuilder类进行了实验,但无法弄清楚如何合并我的自定义xml布局和中性按钮.
如何才能做到这一点?
目前有......
public class MelsMessage extends DialogPreference {
Button bMessage;
EditText eMessage;
TextView tMessage;
public MelsMessage(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
protected View onCreateDialogView() {
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
View view = layoutInflater.inflate(R.layout.dialog_pref_mess, null);
//UI elements
bMessage = (Button) view.findViewById(R.id.buttonMessage);
eMessage = (EditText) view.findViewById(R.id.edittextMessage);
tMessage = (TextView) view.findViewById(R.id.textviewMessage);
return view;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个图像按钮,我想采取整个设备的宽度.我使用的图像src不像按钮那么长.默认似乎是将它与按钮的cener对齐.相反,我想将它对齐到左边.我尝试过使用布局重力但没有响应.
这是代码..
<LinearLayout
android:id = "@+id/llRoot"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left" >
<ImageButton
android:id="@+id/ibSend"
android:layout_gravity="left"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/send" >
</ImageButton>
Run Code Online (Sandbox Code Playgroud)
android ×10
preferences ×2
alignment ×1
dialog ×1
facebook ×1
imagebutton ×1
proguard ×1
styles ×1