csh_34 2013-10-08 08:33 采纳率: 0%
浏览 984

android程序中报病毒的错误

我在Play store 中加载了一个程序,有评论说有一个病毒,有时候强行关闭电话后自己会重新启动。应用程序的代码非常简单:只有一个activity ,还有几个spots,要么能听到,要么设置为铃声。
程序中的代码:

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" />

没网也能正常运行,但是在google play store 中有一个直接的链接能链到我的开发页面,为避免程序崩溃,我使用下面的代码解决:

(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;
    }
  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-02-25 19:33
    关注

    该回答引用ChatGPT

    根据提供的代码,我没有发现程序中存在任何病毒或恶意代码。这个程序的功能似乎是允许用户将指定的音频文件设置为铃声或提示音。程序使用了一些权限,如写入外部存储和访问互联网等,这些权限在程序中都有合理的用途。另外,程序还检查了网络连接状态,以便在没有网络连接时避免崩溃。


    关于程序在某些情况下会强制关闭电话并自动重新启动的问题,这可能是由于手机设备本身的问题,而不是由于程序的代码问题。建议尝试在其他设备上测试该应用程序,以确定是否存在相同的问题。同时,可以尝试在手机上清除缓存和数据,或者卸载应用程序后重新安装,以查看是否可以解决问题。如果问题仍然存在,请联系应用程序开发者寻求进一步的帮助和支持。

    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示