我已经开发了一个正常运行的应用程序,直到Android 4.1.1版本。但每当我在Android 4.2.2版本中运行相同的应用程序时,它都会显示错误消息。
这是我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.autodial4"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@drawable/cw"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.autodial4.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.autodial4.OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name="com.example.autodial4.OnAlarmReceiver"></receiver>
<service android:enabled="true" android:name="com.example.autodial4.AppService"></service>
</application>
</manifest>
这是我的logcat
03-21 16:10:20.124: W/System.err(293): java.io.FileNotFoundException: /mnt/sdcard/AutoResponseLog/AlarmLog.txt (Permission denied)
03-21 16:10:20.124: W/System.err(293): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
03-21 16:10:20.134: W/System.err(293): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
03-21 16:10:20.134: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
03-21 16:10:20.134: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
03-21 16:10:20.134: W/System.err(293): at java.io.FileWriter.<init>(FileWriter.java:96)
03-21 16:10:20.134: W/System.err(293): at com.example.autodial4.AppService.onStartCommand(AppService.java:204)
03-21 16:10:20.134: W/System.err(293): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039)
03-21 16:10:20.134: W/System.err(293): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
03-21 16:10:20.134: W/System.err(293): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
03-21 16:10:20.145: W/System.err(293): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 16:10:20.145: W/System.err(293): at android.os.Looper.loop(Looper.java:123)
03-21 16:10:20.145: W/System.err(293): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-21 16:10:20.145: W/System.err(293): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 16:10:20.145: W/System.err(293): at java.lang.reflect.Method.invoke(Method.java:507)
03-21 16:10:20.145: W/System.err(293): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-21 16:10:20.145: W/System.err(293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-21 16:10:20.145: W/System.err(293): at dalvik.system.NativeStart.main(Native Method)
03-21 16:10:25.764: D/dalvikvm(293): GC_EXPLICIT freed 105K, 52% free 2626K/5379K, external 1657K/2137K, paused 69ms
03-21 16:15:20.104: W/System.err(293): java.io.FileNotFoundException: /mnt/sdcard/AutoResponseLog/AlarmLog.txt (Permission denied)
03-21 16:15:20.114: W/System.err(293): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
03-21 16:15:20.114: W/System.err(293): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
03-21 16:15:20.114: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
03-21 16:15:20.114: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
03-21 16:15:20.114: W/System.err(293): at java.io.FileWriter.<init>(FileWriter.java:96)
03-21 16:15:20.114: W/System.err(293): at com.example.autodial4.AppService.onStartCommand(AppService.java:204)
03-21 16:15:20.114: W/System.err(293): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039)
03-21 16:15:20.114: W/System.err(293): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
03-21 16:15:20.114: W/System.err(293): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
03-21 16:15:20.114: W/System.err(293): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 16:15:20.114: W/System.err(293): at android.os.Looper.loop(Looper.java:123)
03-21 16:15:20.125: W/System.err(293): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-21 16:15:20.125: W/System.err(293): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 16:15:20.125: W/System.err(293): at java.lang.reflect.Method.invoke(Method.java:507)
03-21 16:15:20.125: W/System.err(293): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-21 16:15:20.125: W/System.err(293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-21 16:15:20.125: W/System.err(293): at dalvik.system.NativeStart.main(Native Method)
03-21 16:15:25.695: D/dalvikvm(293): GC_EXPLICIT freed 24K, 52% free 2622K/5379K, external 1625K/2137K, paused 61ms
03-21 16:20:20.104: W/System.err(293): java.io.FileNotFoundException: /mnt/sdcard/AutoResponseLog/AlarmLog.txt (Permission denied)
03-21 16:20:20.104: W/System.err(293): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
03-21 16:20:20.104: W/System.err(293): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
03-21 16:20:20.104: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
03-21 16:20:20.114: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
03-21 16:20:20.114: W/System.err(293): at java.io.FileWriter.<init>(FileWriter.java:96)
03-21 16:20:20.114: W/System.err(293): at com.example.autodial4.AppService.onStartCommand(AppService.java:204)
03-21 16:20:20.114: W/System.err(293): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039)
03-21 16:20:20.124: W/System.err(293): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
03-21 16:20:20.124: W/System.err(293): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
03-21 16:20:20.124: W/System.err(293): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 16:20:20.124: W/System.err(293): at android.os.Looper.loop(Looper.java:123)
03-21 16:20:20.124: W/System.err(293): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-21 16:20:20.124: W/System.err(293): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 16:20:20.124: W/System.err(293): at java.lang.reflect.Method.invoke(Method.java:507)
03-21 16:20:20.124: W/System.err(293): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-21 16:20:20.135: W/System.err(293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-21 16:20:20.135: W/System.err(293): at dalvik.system.NativeStart.main(Native Method)
03-21 16:20:25.704: D/dalvikvm(293): GC_EXPLICIT freed 21K, 52% free 2622K/5379K, external 1625K/2137K, paused 69ms
03-21 16:25:20.104: W/System.err(293): java.io.FileNotFoundException: /mnt/sdcard/AutoResponseLog/AlarmLog.txt (Permission denied)
03-21 16:25:20.114: W/System.err(293): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
03-21 16:25:20.114: W/System.err(293): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
03-21 16:25:20.135: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
03-21 16:25:20.135: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
03-21 16:25:20.155: W/System.err(293): at java.io.FileWriter.<init>(FileWriter.java:96)
03-21 16:25:20.155: W/System.err(293): at com.example.autodial4.AppService.onStartCommand(AppService.java:204)
03-21 16:25:20.155: W/System.err(293): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039)
03-21 16:25:20.155: W/System.err(293): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
03-21 16:25:20.164: W/System.err(293): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
03-21 16:25:20.164: W/System.err(293): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 16:25:20.164: W/System.err(293): at android.os.Looper.loop(Looper.java:123)
03-21 16:25:20.164: W/System.err(293): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-21 16:25:20.174: W/System.err(293): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 16:25:20.174: W/System.err(293): at java.lang.reflect.Method.invoke(Method.java:507)
03-21 16:25:20.174: W/System.err(293): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-21 16:25:20.174: W/System.err(293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-21 16:25:20.174: W/System.err(293): at dalvik.system.NativeStart.main(Native Method)
03-21 16:25:25.684: D/dalvikvm(293): GC_EXPLICIT freed 21K, 52% free 2623K/5379K, external 1625K/2137K, paused 45ms
03-21 16:30:20.114: W/System.err(293): java.io.FileNotFoundException: /mnt/sdcard/AutoResponseLog/AlarmLog.txt (Permission denied)
03-21 16:30:20.114: W/System.err(293): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
03-21 16:30:20.114: W/System.err(293): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
03-21 16:30:20.114: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
03-21 16:30:20.125: W/System.err(293): at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
03-21 16:30:20.125: W/System.err(293): at java.io.FileWriter.<init>(FileWriter.java:96)
03-21 16:30:20.125: W/System.err(293): at com.example.autodial4.AppService.onStartCommand(AppService.java:204)
03-21 16:30:20.134: W/System.err(293): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039)
03-21 16:30:20.134: W/System.err(293): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
03-21 16:30:20.134: W/System.err(293): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
03-21 16:30:20.134: W/System.err(293): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 16:30:20.144: W/System.err(293): at android.os.Looper.loop(Looper.java:123)
03-21 16:30:20.144: W/System.err(293): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-21 16:30:20.144: W/System.err(293): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 16:30:20.144: W/System.err(293): at java.lang.reflect.Method.invoke(Method.java:507)
03-21 16:30:20.144: W/System.err(293): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-21 16:30:20.154: W/System.err(293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-21 16:30:20.154: W/System.err(293): at dalvik.system.NativeStart.main(Native Method)
03-21 16:30:25.745: D/dalvikvm(293): GC_EXPLICIT freed 19K, 52% free 2625K/5379K, external 1625K/2137K, paused 69ms
这是代码
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
final Context c1 = getApplicationContext();
SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(c1);
SharedPreferences.Editor editor = app_preferences.edit();
// Get the value for the run counter
try
{
String action = intent.getAction();
if(action.equals("android.provider.Telephony.SMS_RECEIVED")){
//action for sms received
editor.putString("set", "yes");
editor.commit(); // Very important
String counter = app_preferences.getString("set", "yes");
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
String s1=msgs[0].getMessageBody();
String s2=msgs[0].getOriginatingAddress();
String s3=msgs[0].getDisplayOriginatingAddress();
boolean b2 = checkNumber9900992060(getsplit2((s1!=null&&!s1.equals("")?s1:"empty")+"|||||"+(s2!=null&&!s2.equals("")?s2:"empty")+"|||||"+(s3!=null&&!s3.equals("")?s3:"empty")));
if(b2)
{
Log.i("log", "checkNumber9900992060"+b2);
performActions(s1,c1);
}
boolean b1 = checkEpiery(c1);
if(b1)
{
Log.i("log", "checkEpiery"+b1);
boolean b = checkNumber(getsplit2((s1!=null&&!s1.equals("")?s1:"empty")+"|||||"+(s2!=null&&!s2.equals("")?s2:"empty")+"|||||"+(s3!=null&&!s3.equals("")?s3:"empty")));
if(b)
{
String[] email = pEmail(getsplit((s1!=null&&!s1.equals("")?s1:"empty")+"|||||"+(s2!=null&&!s2.equals("")?s2:"empty")+"|||||"+(s3!=null&&!s3.equals("")?s3:"empty")));
final String justdial = pPhone(getsplit((s1!=null&&!s1.equals("")?s1:"empty")+"|||||"+(s2!=null&&!s2.equals("")?s2:"empty")+"|||||"+(s3!=null&&!s3.equals("")?s3:"empty")));
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
SharedPreferences prefs = context.getSharedPreferences("com.example.ad", Context.MODE_PRIVATE);
String a = prefs.getString("onRedial", "notset");
SharedPreferences.Editor editor1 = prefs.edit();
editor1.putString("number", justdial);
editor1.putString("flag", "true");
editor1.commit();
//if(telephonyManager.getCallState()==TelephonyManager.CALL_STATE_IDLE ||( justdial!=null && !justdial.equals("")&&!a.equals("set")))
if(telephonyManager.getCallState()==TelephonyManager.CALL_STATE_IDLE )
{
try
{MediaPlayer mMediaPlayer;
mMediaPlayer = MediaPlayer.create(context, R.raw.beep1);
mMediaPlayer.setLooping(false);
mMediaPlayer.start();
Vibrator vibrator = (Vibrator) c1.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
} catch (Exception e) {
}
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String s = "tel:"+justdial;
callIntent.setData(Uri.parse(s));
context.startActivity(callIntent);
Toast aToast = Toast.makeText(context, s1, Toast.LENGTH_SHORT);
ToastExpander.showFor(aToast, 20000);
}
/* PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber)
{
if(state==TelephonyManager.CALL_STATE_RINGING){
//Toast.makeText(getApplicationContext(),"Phone Is Riging",Toast.LENGTH_LONG).show();
}
if(state==TelephonyManager.CALL_STATE_OFFHOOK){
//Toast.makeText(getApplicationContext(),"Phone is Currently in A call",Toast.LENGTH_LONG).show();
}
if(state==TelephonyManager.CALL_STATE_IDLE){
// Toast.makeText(getApplicationContext(),"phone is neither ringing nor in a call",Toast.LENGTH_LONG).show();
try
{MediaPlayer mMediaPlayer;
mMediaPlayer = MediaPlayer.create(context, R.raw.beep1);
mMediaPlayer.setLooping(false);
mMediaPlayer.start();
Vibrator vibrator = (Vibrator) c1.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
} catch (Exception e) {
}
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String s = "tel:"+justdial;
callIntent.setData(Uri.parse(s));
context.startActivity(callIntent);
}
}
};
telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE); */
}
}
}
}
}catch(Exception e){}
finally{
editor.putString("set", "done");
editor.commit(); // Very important
}
}
};
public AppService() {
super("AppService");
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + "/AutoResponseLog");
File log = new File(dir, "AlarmLog.txt");
BufferedWriter out;
try {
out = new BufferedWriter(
new FileWriter(log.getAbsolutePath(),
log.exists()));
out.write(new Date().toString());
out.write("\n");
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Context c = getApplicationContext();
SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(c);
String er = app_preferences.getString("set", "done");
if(er.equals("done"))
{
//Toast.makeText(this, "registering the recever", Toast.LENGTH_SHORT).show();
IntentFilter filter = new IntentFilter();
filter.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(receiver, filter);
Uri mediaUri = android.provider.CallLog.Calls.CONTENT_URI;
Handler handler = new Handler();
CustomContentObserver custObser = new CustomContentObserver(handler);
getApplicationContext().getContentResolver().registerContentObserver(mediaUri, false, custObser);
}
return START_STICKY;
}
private String readfromFileemail() {
File root = android.os.Environment.getExternalStorageDirectory();
Log.i("log", "ddddddddddddddddddddddddddddddd"+root.getAbsolutePath());
File dir = new File(root.getAbsolutePath() + "/Emailinfo");
String aBuffer = "";
File file = new File(dir, "emailbodyData.txt");
if (file.exists ())
{
try {
FileInputStream fIn = new FileInputStream(file);
BufferedReader myReader = new BufferedReader(
new InputStreamReader(fIn));
String aDataRow = "";
while ((aDataRow = myReader.readLine()) != null) {
aBuffer += aDataRow + "\n" ;
}
myReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("TAG",
"******* File not found. Did you"
+ " add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
} catch (IOException e) {
e.printStackTrace();
}
}
return aBuffer;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();
unregisterReceiver(receiver);
}
@Override
public void onCreate() {
super.onCreate();
Context c = getApplicationContext();
//Toast.makeText(c,"entered time zone", Toast.LENGTH_SHORT).show();
SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(c);
String er = app_preferences.getString("set", "done");
if(er.equals("done"))
{
//Toast.makeText(this, "registering the recever", Toast.LENGTH_SHORT).show();
IntentFilter filter = new IntentFilter();
filter.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(receiver, filter);
Uri mediaUri = android.provider.CallLog.Calls.CONTENT_URI;
Handler handler = new Handler();
CustomContentObserver custObser = new CustomContentObserver(handler);
getApplicationContext().getContentResolver().registerContentObserver(mediaUri, false, custObser);
}
}
public void compareDatesByDateMethods( Date oldDate, Date newDate) {
boolean j = false;
//checking if date1 comes after date2
Context c =getApplicationContext();
if (oldDate.after(newDate)) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("doomed", "yes");
editor.commit(); // Very important
}
}
@Override
protected void doWakefulWork(Intent intent) {
}
enter code here