微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

据报道,我的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(或其他类似库)的下一个版本,以帮助您跟踪崩溃.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐