小编kum*_*eer的帖子

如何从服务器下载文件并将其保存在Android的SD卡中的特定文件夹中?

我的Android应用程序中有一个要求.我需要以编程方式下载并保存SD卡特定文件夹中的文件.我开发了源代码,这是

String DownloadUrl = "http://myexample.com/android/";
     String fileName = "myclock_db.db";

    DownloadDatabase(DownloadUrl,fileName);

    // and the method is

public void DownloadDatabase(String DownloadUrl, String fileName) {
    try {
        File root = android.os.Environment.getExternalStorageDirectory();
        File dir = new File(root.getAbsolutePath() + "/myclock/databases");
        if(dir.exists() == false){
             dir.mkdirs();  
        }

        URL url = new URL("http://myexample.com/android/");
        File file = new File(dir,fileName);

        long startTime = System.currentTimeMillis();
        Log.d("DownloadManager" , "download url:" +url);
        Log.d("DownloadManager" , "download file name:" + fileName);

        URLConnection uconn = url.openConnection();
        uconn.setReadTimeout(TIMEOUT_CONNECTION);
        uconn.setConnectTimeout(TIMEOUT_SOCKET);

        InputStream is = uconn.getInputStream();
        BufferedInputStream bufferinstream = new …
Run Code Online (Sandbox Code Playgroud)

android android-input-method android-download-manager

24
推荐指数
1
解决办法
5万
查看次数

在Android中以编程方式解压缩文件

我正在下载一个zip文件夹并保存在我的Android设备中的特定文件夹中.我的应用程序没有访问该文件夹,因为它是压缩的.我想从服务器下载后解压缩文件夹并保存在特定文件夹中.

我的代码在这里:

public void DownloadDatabase(String DownloadUrl, String fileName) {
    try {
        File root = android.os.Environment.getExternalStorageDirectory();
        File dir = new File(root.getAbsolutePath() + "/timy/databases");
        if(dir.exists() == false){
             dir.mkdirs();  
        }

        URL url = new URL("http://myexample.com/android/timy.zip");
        File file = new File(dir,fileName);

        long startTime = System.currentTimeMillis();
        Log.d("DownloadManager" , "download url:" +url);
        Log.d("DownloadManager" , "download file name:" + fileName);

        URLConnection uconn = url.openConnection();
        uconn.setConnectTimeout(TIMEOUT_SOCKET);

        InputStream is = uconn.getInputStream();

        ZipInputStream zipinstream = new ZipInputStream(new BufferedInputStream(is));
        ZipEntry zipEntry;

        while((zipEntry = zipinstream.getNextEntry()) != null){
            String zipEntryName = zipEntry.getName();
            File …
Run Code Online (Sandbox Code Playgroud)

java android android-emulator android-download-manager

5
推荐指数
2
解决办法
2万
查看次数

从IOS应用程序中的字符串中删除"\"

我从带有反斜杠字符的json响应中获取一个url作为字符串.我想从url中删除'\'字符.我构建了代码,但它无法正常工作.代码在这里..

 NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
    NSString* encodedString = [responseData stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSLog(@"Response ==> %@" ,encodedString);

       // here encodedString is a url which is showing crctly in output and need to trim the \ character.

       // NSString* str = [NSString stringWithFormat: @"encodedString"];
       // str = [str stringByReplacingOccurrencesOfString:@"?" withString:@""];
       // NSLog(@"Response ==> %@" , str);

    encodedString = [encodedString stringByReplacingOccurrencesOfString:@"\\" withString:@""];
        NSLog(@"Response ==> %@" ,encodedString);
Run Code Online (Sandbox Code Playgroud)

但我无法删除这些字符.任何人都可以帮助我摆脱这个问题..提前谢谢.

iphone objective-c html-escape-characters

2
推荐指数
1
解决办法
7519
查看次数

从webservices url获取密码并通过该密码访问

我有一个附加了访问代码的Webservices URL.我需要将访问代码发布到webservices url并获取json响应.我正在使用正确的访问代码和错误的访问代码获得json响应.我没有得到问题所在.我需要在输入错误密码时显示警报,这是我的代码..

  NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@",[txtsecurecode text]];
        NSLog(@"PostData: %@",post);
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

      [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://my example.com/Accountservice/Security/ValidateAccess?accesscode=abcdtype=1"]]];

        NSURL *url;

  // I need to parse it into url here .  

        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        NSURLConnection *conn= [[NSURLConnection alloc] initWithRequest:request delegate:self];
        if(conn)
        {
            NSLog(@"Connection Successful");
        }
        else
        {
            NSLog(@"Connection could not be made");
        }

    NSString *responseData = [[NSString …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa objective-c ios

2
推荐指数
1
解决办法
1390
查看次数

如何保存iPhone应用程序的用户首选项?

我正在构建一个应用程序,需要在打开应用程序之前输入访问凭据(组织代码,访问代码).当用户第一次输入访问权限时,我们需要保存首选项.当用户再次打开应用程序时,他自动需要继续使用应用程序,但不能使用访问凭据.

我在这里构建代码

log cat中没有错误,但不保存首选项.我需要在用户打开应用程序时保存首选项并加载.我在代码中做错了吗?

iphone settings xcode objective-c

1
推荐指数
1
解决办法
1040
查看次数

如何限制iOS应用程序中textfield的字符最多5个字符?

我想限制textFieldIOS应用程序中的字符.我尝试了Stack Overflow中给出的所有方法,所以我问这个问题.

这里我使用了一个Label(安全代码)和一个textfield(5个字符).

我在viewcontroller.m文件中给出了以下代码,但没有工作.

   myTextField.delegate = self

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{
   NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];

   return !([newString length] > 5);
}
Run Code Online (Sandbox Code Playgroud)

ios4 ios ios5

0
推荐指数
1
解决办法
5665
查看次数