0
我的應用程序 - 使用包含移動號碼和每個消息的掃描器讀取文本文件。 按照文本文件向每個移動號碼發送短信。 每次沒有短信從20到140nos,大約需要8到10分鐘。Wakelock沒有保持CPU運行
如果通過持續的觸摸交互來保持CPU運行,所有的SMS都會正確發送。沒問題。
如果我不觸摸並將設備放在一邊,只發送15-20條SMS。
我試圖使用 1保持屏幕 - 不工作。 2使用部分喚醒鎖 - 不工作 3使用部分喚醒鎖與處理器在10分鐘後釋放喚醒鎖 - 仍然只發送15 - 20條短信,但10分鐘後喚醒鎖。 4用於保持屏幕部分喚醒鎖定 - 仍然與上述一樣,不工作。
這是我的代碼。
public class Ardtxt extends Activity {
private Button buttonsendsms;
String gg = "my app";
File fileexists ;
String mdn, msg;
String tomdn = "9123456789";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_ardtxt);
//*********************
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Button buttonsendsms = (Button) findViewById(R.id.buttonsendsms);
buttonsendsms.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
final WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"ardtxtwakelock");
wakeLock.acquire();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "All SMS are sent.",Toast.LENGTH_LONG).show();
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("9123456789", null, "wake lock released", null, null);
wakeLock.release();
}
}, 600000);
Toast.makeText(getApplicationContext(), "start" , Toast.LENGTH_LONG).show();
Log.d("chk","app start");
File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"kk");
directory.mkdirs();
Log.d("mytxt app App", Environment.getExternalStorageDirectory()+File.separator+"kk");
fileexists = new File(Environment.getExternalStorageDirectory()+File.separator+"kk"+File.separator, "Sample1.txt");
if (fileexists.exists()) {
//Do action
Log.d("app exxxxx",String.valueOf(fileexists));
Toast.makeText(getApplicationContext(), "subject file exists" , Toast.LENGTH_LONG).show();
System.out.println("file exists so can be used by us");
Log.d("Ketan check", "Sample1.txt exists");
try {
Readtxtfile();
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Log.d(gg,"Exception : file not found");
e.printStackTrace();
Toast.makeText(getApplicationContext(), "crpg file not found" , Toast.LENGTH_LONG).show();
}
}
}
});}
讓我知道我缺少什麼或者爲什麼部分喚醒鎖不保持CPU活着。
謝謝。
您是否向清單添加了相關的喚醒鎖定權限?如果你這樣做了,那麼我會嘗試將SMS發送代碼移動到一個線程(或者AsyncTask,或者更好,帶有線程的服務) –