据报道,我的Android应用程序有病毒

我已经在Play商店上传一个应用程序,我收到了一些评论,其中包含病毒,有时会强制移动设备自行重启.我的应用程序中的代码非常简单:只有一个活动有几个点,你可以听到它们或将它们设置为铃声.你能告诉我什么吗?

我的应用代码

b1_2.setonClickListener(new View.OnClickListener() {
  public void onClick(View v) {
    if(saveas(soundid,save_name)){
      Toast.makeText(Main.this,"The sound was set as ringtone!",Toast.LENGTH_LONG).show();
    };
  }
});
public boolean saveas(int ressound,String filename){
  byte[] buffer=null;
  InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
  int size=0;
  try {
    size = fIn.available();
    buffer = new byte[size];
    fIn.read(buffer);
    fIn.close();
  } catch (IOException e) {
    // Todo Auto-generated catch block
    return false;
  }
  String path="/sdcard/media/ringtones/";
  boolean exists = (new File(path)).exists();
  if (!exists){new File(path).mkdirs();}
  FileOutputStream save;
  try {
    save = new FileOutputStream(path+filename);
    save.write(buffer);
    save.flush();
    save.close();
  } catch (FileNotFoundException e) {
    // Todo Auto-generated catch block
    return false;
    } catch (IOException e) {
      // Todo Auto-generated catch block
      return false;
    }
    sendbroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse("file://"+path+filename)));
    File k = new File(path,filename);
    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA,k.getAbsolutePath());
    values.put(MediaStore.MediaColumns.TITLE,"clip_"+save_name);
    values.put(MediaStore.MediaColumns.MIME_TYPE,"audio/mp3");
    values.put(MediaStore.Audio.Media.ARTIST,"clip");
    values.put(MediaStore.Audio.Media.IS_ringtone,true);
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION,true);
    values.put(MediaStore.Audio.Media.IS_ALARM,true);
    values.put(MediaStore.Audio.Media.IS_MUSIC,true);
    //Insert it into the database
    Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
    getContentResolver().delete(uri,MediaStore.MediaColumns.DATA + "=\"" +
      k.getAbsolutePath() + "\"",null);
    Uri newUri= this.getContentResolver().insert(uri,values);
    ringtoneManager.setActualDefaultringtoneUri(
      this,ringtoneManager.TYPE_ringtone,newUri);
    return true;
  }

需要的权限是:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
     <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

它没有互联网,但我只是直接链接到谷歌游戏商店的开发者页面,为了避免崩溃,我使用了这个功能

(if link is pressed)
  if (isOnline()){
    open page
} else {
  do nothing
}
public boolean isOnline() {
        boolean connectedWifi = false;
        boolean connectedMobile = false;

        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] networks = cm.getAllNetworkInfo();
        for (NetworkInfo ni : networks) {
            if ("WIFI".equalsIgnoreCase(ni.getTypeName()))
                if (ni.isConnected())
                    connectedWifi = true;
            if ("MOBILE".equalsIgnoreCase(ni.getTypeName()))
                if (ni.isConnected())
                    connectedMobile = true;
        }
        return connectedWifi || connectedMobile;
    }

解决方法

首先,你的Android应用程序“有病毒”的概念很愚蠢.如果您的应用中存在恶意代码,那么这是因为您开发了包含恶意代码的应用.

这里发生的事情很可能是你的应用程序中有一个BUG.更糟糕的是,您的用户使用的Android SDK也有一个错误(因为操作系统崩溃,永远不会发生).如果不经过并分析您的所有代码,这里的任何人都很难直接回答代码和/或Android SDK中的错误.

我建议弄清楚这个bug经历过哪些设备和SDK版本,然后我会开始在这些设备/ SDK上测试应用程序.由于您认为该错误可能与互联网连接有关,因此请在启用,禁用和弱连接的情况下测试应用程序.请注意,您可能遇到以前Android SDK中的已知错误.

您还可以启动安装了Crittercism(或其他类似库)的下一个版本,以帮助您跟踪崩溃.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...