我试图在代码下运行,它给出了异常说法:
java.lang.RuntimeException: Unable to start service com.example.testfeeds.UpdateWidgetService@410a33c8 with Intent { cmp=com.example.testfeeds/.UpdateWidgetService (has extras) }: android.os.NetworkOnMainThreadException
Run Code Online (Sandbox Code Playgroud)
据我所知,Android的新版本将不允许主线程中的网络操作.人们建议我使用Async Task,但我不知道如何使用它.有人可以在下面的代码中显示我吗?
提前致谢
public class WidgetService extends Service {
/*
* So pretty simple just defining the Adapter of the listview
* here Adapter is ListProvider
* */
/*@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
int appWidgetId = intent.getIntExtra(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
return (new ListProvider(this.getApplicationContext(), intent));
}*/
public static int numberOfItems=0;
//numberOfItems=0;
private static String LOG = "testwidgets";
ArrayList<String> feedsPubDate;
@SuppressWarnings("deprecation")
@Override
public void onStart(Intent intent, int …Run Code Online (Sandbox Code Playgroud) 我正在尝试将.so文件包含在我的Android Studio项目.jniLibs文件夹中但是得到以下错误,我该如何克服它?
错误:任务':app:compileDebugNdk'的执行失败.错误:当前插件中不推荐使用NDK集成.考虑尝试新的实验插件.有关详细信息,请参阅http://tools.android.com/tech-docs/new-build-system/gradle-experimental.在gradle.properties中设置"android.useDeprecatedNdk = true"以继续使用当前的NDK集成.
我找不到gradle.properties任何地方?我在哪里可以找到或有任何解决方法?
谢谢
下面是返回String中数据计数器值的类.我想将String格式化为KB,MB和GB
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView infoView = (TextView)findViewById(R.id.traffic_info);
String info = "";
long getmobilerxbytes = TrafficStats.getMobileRxBytes();
long getmobilerxpackets = TrafficStats.getMobileRxPackets();
long getmobiletxbytes = TrafficStats.getMobileTxBytes();
long getmobiletxpackets = TrafficStats.getMobileTxPackets();
long totalrxbytes = TrafficStats.getTotalRxBytes();
long totalrxpackets = TrafficStats.getTotalRxPackets();
long totaltxbytes = TrafficStats.getTotalTxBytes();
long totaltxpackets = TrafficStats.getTotalTxPackets();
info += "Mobile Interface:\n";
info += ("\tReceived: " + getmobilerxbytes + " bytes / " + getmobilerxpackets + " packets\n");
info += ("\tTransmitted: " + …Run Code Online (Sandbox Code Playgroud) 我想以编程方式设置锁定屏幕密码,然后在执行循环时删除。我已经成功添加了设备管理,有人可以帮助我从应用程序本身设置和取消锁定屏幕密码。以下是我的设备管理工作代码
public class DevicePolicyDemoActivity extends Activity {
static final String TAG = "DevicePolicyDemoActivity";
static final int ACTIVATION_REQUEST = 47; // identifies our request id
DevicePolicyManager devicePolicyManager;
ComponentName demoDeviceAdmin;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Initialize Device Policy Manager service and our receiver class
devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
demoDeviceAdmin = new ComponentName(this, DemoDeviceAdminReceiver.class);
Intent intent = new Intent(
DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
demoDeviceAdmin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"Your boss told you to do this"); …Run Code Online (Sandbox Code Playgroud) 我试图构建我的应用程序,我收到以下错误,不确定,如何解决它
1) Error:(49, 91) error: cannot find symbol variable BOOKMARKS_URI
2) Error:(56, 94) error: cannot find symbol variable BookmarkColumns
3) Error:(3780, 27) error: cannot find symbol method setLatestEventInfo(Context,String,String,PendingIntent)
Run Code Online (Sandbox Code Playgroud)
任何想法,如何克服它?
谢谢
我在新的Android ARM 64设备上面临很少的库错误,有没有办法识别ARM 64设备,以便我可以绕过我的代码用于那些特定的设备?
谢谢
我必须为所有Switch案例定义ENUM.我不确定如何将enums与职位联系起来.以下是我的代码:
public enum Choice {
A, B, C
}
public void selectItem(int position) {
switch (position) {
// Dashboard
case 0:
break;
case 1:
break;
}
}
Run Code Online (Sandbox Code Playgroud) 我在表格中使用了一个微调框。但是当我放下微调器时,它的颜色与背景色匹配。如何在Android的下拉菜单中添加阴影
是否可以从字符串中找到#hashtag和"http://"链接并为其着色?我在Android中使用它.
public void setTitle(String title) {
this.title = title;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
如何将微调器中的第一个值(默认值)设置为空.意味着,直到用户从列表中选择值,微调器才会没有值.我在下面试过
list.add("");
Run Code Online (Sandbox Code Playgroud)
但是,它不会起作用.以下是我的代码:
if(values.contains("options")){
spinner.setOnItemSelectedListener(MyClass.this);
List<String> list = new ArrayList<String>();
list.add("");
list.add("Test");
list.add("Working");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, list) {};
adapter.setDropDownViewResource(R.layout.custom_spinner_list);
spinner.setAdapter(adapter);
}
}
Run Code Online (Sandbox Code Playgroud) 如何在Android中格式化我的日期.我有String,它以下面的格式获取日期
String format = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
Run Code Online (Sandbox Code Playgroud)
产量
25 Nov 2013 17:39:00
Run Code Online (Sandbox Code Playgroud)
我希望以下面的格式转换
dd/mm/yy 5:39PM
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码来获取日期.如何将该格式转换为String?
android ×11
string ×2
arm ×1
asynchronous ×1
date ×1
date-format ×1
device-admin ×1
dropdown ×1
enums ×1
java ×1
screen-lock ×1
service ×1