Example usage for android.content Context MODE_WORLD_WRITEABLE

List of usage examples for android.content Context MODE_WORLD_WRITEABLE

Introduction

In this page you can find the example usage for android.content Context MODE_WORLD_WRITEABLE.

Prototype

int MODE_WORLD_WRITEABLE

To view the source code for android.content Context MODE_WORLD_WRITEABLE.

Click Source Link

Document

File creation mode: allow all other applications to have write access to the created file.

Usage

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static void sendTestNotification(Context context) {

    if (!TEST_NOTIFICATION) {
        return;/*  w ww  .j  av a 2s. c om*/
    }

    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    Intent markRead = new Intent(context, MarkReadService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    String shortText = "Test Test";
    String longText = "Here is a test for Test's notifications";

    Intent resultIntent = new Intent(context, RedirectToMentions.class);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    NotificationCompat.Builder mBuilder;

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText)
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        sendAlertToPebble(context, shortText, shortText);
    }

    // Light Flow notification
    sendToLightFlow(context, shortText, shortText);

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            e.printStackTrace();
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    Intent reply = null;
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "daiv" + " ").build();

    // Create the notification action
    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
            replyPending).addRemoteInput(remoteInput).build();

    NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);

    mBuilder.addAction(replyAction);
    mBuilder.addAction(action.build());

    // Build the notification and issues it with notification manager.
    notificationManager.notify(1, mBuilder.build());

    // if we want to wake the screen on a new message
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void sendTestNotification(Context context) {

    if (!TEST_NOTIFICATION) {
        return;/*from ww w  . j  a  v  a  2  s .  co m*/
    }

    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences(
            "com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    Intent markRead = new Intent(context, MarkReadService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    String shortText = "Test Talon";
    String longText = "Here is a test for Talon's notifications";

    Intent resultIntent = new Intent(context, RedirectToMentions.class);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    NotificationCompat.Builder mBuilder;

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText)
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        sendAlertToPebble(context, shortText, shortText);
    }

    // Light Flow notification
    sendToLightFlow(context, shortText, shortText);

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            e.printStackTrace();
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    Intent reply = new Intent(context, NotificationCompose.class);
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "lukeklinker" + " ")
            .build();

    // Create the notification action
    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
            replyPending).addRemoteInput(remoteInput).build();

    NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);

    mBuilder.addAction(replyAction);
    mBuilder.addAction(action.build());

    // Build the notification and issues it with notification manager.
    notificationManager.notify(1, mBuilder.build());

    // if we want to wake the screen on a new message
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String RunReboot(OutputStream out, String sCallBackIP, String sCallBackPort) {
    String sRet = "";
    Context ctx = contextWrapper.getApplicationContext();

    try {/* w  ww.  j a  v a  2 s.c  o  m*/
        if ((sCallBackIP != null) && (sCallBackPort != null) && (sCallBackIP.length() > 0)
                && (sCallBackPort.length() > 0)) {
            FileOutputStream fos = ctx.openFileOutput("update.info",
                    Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
            String sBuffer = sCallBackIP + "," + sCallBackPort + "\rSystem rebooted\r";
            fos.write(sBuffer.getBytes());
            fos.flush();
            fos.close();
            fos = null;
        }
    } catch (FileNotFoundException e) {
        sRet = sErrorPrefix + "Callback file creation error [rebt] call failed " + e.getMessage();
        e.printStackTrace();
    } catch (IOException e) {
        sRet = sErrorPrefix + "Callback file error [rebt] call failed " + e.getMessage();
        e.printStackTrace();
    }

    try {
        // Tell all of the data channels we are rebooting
        ((ASMozStub) this.contextWrapper).SendToDataChannel("Rebooting ...");

        pProc = Runtime.getRuntime().exec(this.getSuArgs("reboot"));
        RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
        outThrd.start();
        outThrd.joinAndStopRedirect(10000);
    } catch (IOException e) {
        sRet = e.getMessage();
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    return (sRet);
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String StrtUpdtOMatic(String sPkgName, String sPkgFileName, String sCallBackIP, String sCallBackPort) {
    String sRet = "";

    Context ctx = contextWrapper.getApplicationContext();
    PackageManager pm = ctx.getPackageManager();

    Intent prgIntent = new Intent();
    prgIntent.setPackage("com.mozilla.watcher");

    try {/* w  ww  .j  a  v a2s.  c  om*/
        PackageInfo pi = pm.getPackageInfo("com.mozilla.watcher",
                PackageManager.GET_SERVICES | PackageManager.GET_INTENT_FILTERS);
        ServiceInfo[] si = pi.services;
        for (int i = 0; i < si.length; i++) {
            ServiceInfo s = si[i];
            if (s.name.length() > 0) {
                prgIntent.setClassName(s.packageName, s.name);
                break;
            }
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        sRet = sErrorPrefix + "watcher is not properly installed";
        return (sRet);
    }

    prgIntent.putExtra("command", "updt");
    prgIntent.putExtra("pkgName", sPkgName);
    prgIntent.putExtra("pkgFile", sPkgFileName);
    prgIntent.putExtra("reboot", true);

    try {
        if ((sCallBackIP != null) && (sCallBackPort != null) && (sCallBackIP.length() > 0)
                && (sCallBackPort.length() > 0)) {
            FileOutputStream fos = ctx.openFileOutput("update.info",
                    Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
            String sBuffer = sCallBackIP + "," + sCallBackPort + "\rupdate started " + sPkgName + " "
                    + sPkgFileName + "\r";
            fos.write(sBuffer.getBytes());
            fos.flush();
            fos.close();
            fos = null;
            prgIntent.putExtra("outFile", ctx.getFilesDir() + "/update.info");
        } else {
            if (prgIntent.hasExtra("outFile")) {
                System.out.println("outFile extra unset from intent");
                prgIntent.removeExtra("outFile");
            }
        }

        ComponentName cn = contextWrapper.startService(prgIntent);
        if (cn != null)
            sRet = "exit";
        else
            sRet = sErrorPrefix + "Unable to use watcher service";
    } catch (ActivityNotFoundException anf) {
        sRet = sErrorPrefix + "Activity Not Found Exception [updt] call failed";
        anf.printStackTrace();
    } catch (FileNotFoundException e) {
        sRet = sErrorPrefix + "File creation error [updt] call failed";
        e.printStackTrace();
    } catch (IOException e) {
        sRet = sErrorPrefix + "File error [updt] call failed";
        e.printStackTrace();
    }

    ctx = null;

    return (sRet);
}