我需要使用空闲侦听器来监听用户正在使用应用程序或在活动处于活动状态时闲置.当用户不使用应用程序超过十秒钟时,我需要做一些事情.我怎么能让它成为可能?
我已经创建了自己的自定义SurfaceView,它可以自行运行,但是当我尝试将两个放在TabWidget中的单独选项卡上时,无论选择哪个选项卡,都会显示一个,并且它总是首先绘制的SurfaceView应用开始.
为了说明问题,我创建了可以编译显示问题的示例代码.
下面的SurfaceView(称为SurfaceViewCircle)只是创建一个位图,默认情况下绘制一个蓝色圆圈然后显示它.有一个公共方法,changeColour(),它将改变位图中的圆形颜色.
其次,我创建了一个XML布局,它只包含一个SurfaceViewCircle实例.
在Activity类中,我创建了一个TabWidget和主机等.然后我将上面的XML充气两次,但在一个实例中,我将SurfaceViewCircle的颜色更改为红色.一旦应用程序运行,无论我选择哪个选项卡,当应用程序退出并显示蓝色圆圈时,红色圆圈始终显示为例外情况.
有人能指出我在使用SurfaceView时错过了一个步骤吗?
这是活动代码:
public class TestActivity extends Activity {
/** Called when the activity is first created. */
private TabHost mTabHost;
private Context mTabHostContext;
private View surfaceView1, surfaceView2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* Setup tabs
*/
setContentView(R.layout.maintabs);
setupTabHost(); //Prepares the TabHost from code rather than XML;
mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider); //Sets a thin dividing line
mTabHostContext = mTabHost.getContext();
surfaceView1 = LayoutInflater.from(mTabHostContext).inflate(R.layout.surfaceviewindependent, null);
SurfaceViewCircle s = (SurfaceViewCircle)surfaceView1.findViewById(R.id.circle1);
/*
* Change the colour to red …Run Code Online (Sandbox Code Playgroud) 我正在尝试将名为download.pdf的PDF文件附加到我的Android应用程序中的电子邮件中.我首先将文件复制到SDCard,然后将其附加到电子邮件中.
我不是相关的,但我正在测试一个galaxy tab设备.外部存储路径返回mnt/sdcard /
我的代码如下:
public void sendemail() throws IOException {
CopyAssets();
String emailAddress[] = {""};
File externalStorage = Environment.getExternalStorageDirectory();
Uri uri = Uri.fromFile(new File(externalStorage.getAbsolutePath() + "/" + "download.pdf"));
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Text");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
}
public void CopyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.e("tag", e.getMessage());
}
for(String filename : files) {
InputStream in …Run Code Online (Sandbox Code Playgroud) import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
public class FileExplorerActivity extends Activity
{
public static final String TAG="ricky";
Button button;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
button = (Button) findViewById(R.id.but);<<<------------------
if(button == null)
Log.d(TAG, "FileExplorerActivity: button is null");
}
public FileExplorerActivity()
{
Log.d(TAG, "FileExplorer: constructor()");
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个简单的Activity,由另一个使用Intent的活动引入
Intent openFileBrowser = new Intent(this, FileExplorerActivity.class);
try
{
startActivity(openFileBrowser);
}
Run Code Online (Sandbox Code Playgroud)
运行代码后我的LogCat文件说"按钮为空"为什么???
我已经安装了Windows 8发布预览版,我无法安装android USB驱动程序,它说:

和
"第三方INF不包含数字签名信息"
该怎么办?
我想在android中禁用状态栏或通知栏.我用android:theme="@android:style/Theme.NoTitleBar.Fullscreen"它来禁用它但它也使我的标题栏禁用.我怎样才能禁用状态栏?
public class FetchImageAppsActivity extends Activity {
/** Called when the activity is first created. */
public static String urlPath = "http://farm1.static.flickr.com/150/399390737_7a3d508730_b.jpg";
public ImageView imageView;
boolean usingProxy=true;
public String proxyIP="A.B.C.D";
public int proxyPort=80;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView =(ImageView) findViewById(R.id.imageViewFetch);
if(usingProxy==true){
setProxy();
}
try {
fetch(urlPath);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Drawable image = ImageOperations(this,urlPath,"overflow.png");
imageView.setImageDrawable(image);
/* imageView.setMinimumWidth();
imageView.setMinimumHeight(height);
imageView.setMaxWidth(width);
imageView.setMaxHeight(height);
*/
}
private Drawable ImageOperations(Context ctx, String url, …Run Code Online (Sandbox Code Playgroud) 我在Android手机中实现了代码记录视频.此代码适用于2.2,2.3.
但是当我检查ICS代码不起作用?
这里我发布了代码和xml文件.
videorecord.java
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class videorecord extends Activity{
SharedPreferences.Editor pre;
String filename;
CountDownTimer t;
private Camera myCamera;
private MyCameraSurfaceView myCameraSurfaceView;
private MediaRecorder mediaRecorder;
Integer cnt=0;
LinearLayout myButton; …Run Code Online (Sandbox Code Playgroud) android android-intent android-layout android-4.0-ice-cream-sandwich
我试图通过CLLocationManager下面的代码使用当前的城市和国家-
#pragma mark - Core Location Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];
[reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
NSLog(@"Received placemarks: %@", placemarks);
CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];
NSString *countryCode = myPlacemark.ISOcountryCode;
NSString *countryName = myPlacemark.country;
NSString *city1 = myPlacemark.subLocality;
NSString *city2 = myPlacemark.locality;
NSLog(@"My country code: %@, countryName: %@, city1: %@, city2: %@", …Run Code Online (Sandbox Code Playgroud) android ×9
android-4.0-ice-cream-sandwich ×1
cocoa-touch ×1
email ×1
fetch ×1
findviewbyid ×1
image ×1
ios ×1
iphone ×1
java ×1
listener ×1
objective-c ×1
pdf ×1
proxy ×1
python-idle ×1
statusbar ×1
surfaceview ×1
tabs ×1
titlebar ×1
windows-8 ×1