我问过这个问题,但我没有得到答复.
我使用以下代码打开移动数据(3G).
private static void setMobileDataEnabled(Context context, boolean enabled){
try{
ConnectivityManager conman = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
Method setMobileDataEnabledMethod = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(conman, enabled);
}catch(NoSuchMethodException e){e.printStackTrace();}
catch(InvocationTargetException e){e.printStackTrace();}
catch(IllegalAccessException e){e.printStackTrace();}
}
Run Code Online (Sandbox Code Playgroud)
我称之为:
setMobileDataEnabled(getBaseContext(), true/false);
Run Code Online (Sandbox Code Playgroud)
它正确启用/禁用移动数据,但此代码在双SIM卡设备上无法正常工作.我在三星Dual-SIM上的摩托罗拉Razr D1,D3上进行了测试(现在不记得),但这段代码不起作用.一切正常,应用程序不会崩溃.
我试过"getApplicationContext()"和"this"而不是"getBaseContext()",但没有改变.
我了解到Android并非专为双芯片设备设计,这可能是一个问题,因为我无法定位任何SIM卡,所以我无法找到任何技巧或其他任何"修复"代码,我我对吗?
我可以做些什么来在双芯片设备上打开/关闭移动数据?我把在源代码一看,setMobileDataEnabled是"公共",磨片不应该访问它?
我也找到了IConnectivityManager类,但它不是java扩展,我认为它是.aidl或者什么(不记得了),它可以有用吗?
我不知道该怎么办,我需要帮助.
对不起我的英语不好.
谢谢.
我的应用程序上有一些TextViews,我不知道为什么但是该android:gravity属性没有将文本内容集中在运行API 18+(4.3+)的设备上.
我在自定义上使用了代码TextView,这是RelativeLayout的子代:
<com.package.custom.CustomTextFont
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/seekbar"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/seekbar"
android:layout_marginLeft="@dimen/margin_tiny_double"
android:layout_toLeftOf="@+id/seekbar"
android:gravity="center_vertical|left"
android:paddingRight="@dimen/margin_tiny"
android:text="@string/text1"
android:textColor="@color/black"
android:textSize="@dimen/size_text_normal" />
Run Code Online (Sandbox Code Playgroud)
这个代码应该采用这个代码的边缘TextView并将它对齐到顶部和底部并将它放在左边SeekBar,这是有效的,但是TextView变大了,所以android:gravity我将文本居中到中心并从中自取.它工作,但我不知道为什么,文本不在运行android 4.3和4.4的设备的中心左侧.此问题可以在真实设备上以及Eclipse的布局预览(图形布局)上重现.
对API 18+或android:gravity我遗漏的内容进行了哪些更改?
PS:我的目标是项目和AndroidManifest.xml上的API 19
PS2:我的TextView是自定义的,只是为了设置外部font.tff
这就是它在API 17上的样子 -

这就是它在API 18+上的样子

提前致谢!
= UPTADATE =
在我的Manifest上,我将其更改android:targetSdkVersion为17而不是19并且问题消失了,但这是一个"技巧",而不是解决方案,我能做什么,因为它可能是来自API的问题?是的,我有最新版本的API 18和19(今天,01/30/2014).
关于它有几个问题,但我总是读同样的事情:"如果系统需要资源,服务将被杀死"或"你无法构建一个永远运行的服务,因为它在后台运行的越多,就越容易受到影响系统杀死它"等等
我面临的问题是:我的服务运行良好并且正如预期的那样,如果我运行我的应用程序然后退出它我的服务仍在运行,但是当我杀了我的应用程序时(通过转到"最近的应用程序"并转换它离开)服务停止.在这一刻,如果我转到设置>> aplications >>运行,我会看到该服务正在重启.过了一会儿,它回来了,我的服务运行没有问题.
我谷歌它,我找到了一些我能做的事情,但让我们先看看我的代码:
我通过这种方式启动我的服务(点击一下按钮后):
Intent intent = new Intent (MainActivity.this, MyService.class);
startService(intent);
Run Code Online (Sandbox Code Playgroud)
我还有3个额外的整数,所以我有这样的东西:
final Integer i, i2, i3;
i = 5; //for example
i2 = 10; //for example
i3 = 15; //for example
final Intent intent = new Intent (MainActivity.this, MyService.class);
intent.putExtra("INTEGER1", i);
intent.putExtra("INTEGER2", i2);
intent.putExtra("INTEGER3", i3);
startService(intent);
Run Code Online (Sandbox Code Playgroud)
在MyService中,我有以下方面:
public class MyService extends Service
{
AlarmManager am;
BroadcastReceiver br;
PendingIntent pi;
Integer i, i2, i3;
@Override
public void onCreate()
{
super.onCreate();
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
pi = PendingIntent.getBroadcast(this, …Run Code Online (Sandbox Code Playgroud)