List of usage examples for android.content Context MODE_WORLD_READABLE
int MODE_WORLD_READABLE
To view the source code for android.content Context MODE_WORLD_READABLE.
Click Source Link
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondMentions(Context context, int secondAccount) { MentionsDataSource data = MentionsDataSource.getInstance(context); int numberNew = data.getUnreadCount(secondAccount); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;//from w w w. ja v a2 s . c om Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); ; String name = null; String message; String messageLong; String tweetText = null; NotificationCompat.Action replyAction = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; tweetText = data.getNewestMessage(secondAccount); messageLong = "<b>@" + name + "</b>: " + tweetText; largeIcon = getImage(context, name); Intent reply = new Intent(context, NotificationComposeSecondAcc.class); sharedPrefs.edit().putString("from_notification_second", "@" + name).commit(); long id = data.getLastIds(secondAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long_second", id).commit(); sharedPrefs.edit() .putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build(); // Create the notification action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput) .build(); } else { // more than one mention message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (numberNew == 1) { mBuilder.addAction(replyAction); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings)); mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, 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); } // Pebble notification if (context .getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:RhodesService.java
private File downloadPackage(String url) throws IOException { final Context ctx = RhodesActivity.getContext(); final Thread thisThread = Thread.currentThread(); final Runnable cancelAction = new Runnable() { public void run() { thisThread.interrupt();//w ww .jav a 2 s . co m } }; BroadcastReceiver downloadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(ACTION_ASK_CANCEL_DOWNLOAD)) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage("Cancel download?"); AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_POSITIVE, ctx.getText(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { cancelAction.run(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, ctx.getText(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Nothing } }); dialog.show(); } else if (action.equals(ACTION_CANCEL_DOWNLOAD)) { cancelAction.run(); } } }; IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_ASK_CANCEL_DOWNLOAD); filter.addAction(ACTION_CANCEL_DOWNLOAD); ctx.registerReceiver(downloadReceiver, filter); File tmpFile = null; InputStream is = null; OutputStream os = null; try { updateDownloadNotification(url, -1, 0); /* List<File> folders = new ArrayList<File>(); folders.add(Environment.getDownloadCacheDirectory()); folders.add(Environment.getDataDirectory()); folders.add(ctx.getCacheDir()); folders.add(ctx.getFilesDir()); try { folders.add(new File(ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0).dataDir)); } catch (NameNotFoundException e1) { // Ignore } folders.add(Environment.getExternalStorageDirectory()); for (File folder : folders) { File tmpRootFolder = new File(folder, "rhodownload"); File tmpFolder = new File(tmpRootFolder, ctx.getPackageName()); if (tmpFolder.exists()) deleteFilesInFolder(tmpFolder.getAbsolutePath()); else tmpFolder.mkdirs(); File of = new File(tmpFolder, UUID.randomUUID().toString() + ".apk"); Logger.D(TAG, "Check path " + of.getAbsolutePath() + "..."); try { os = new FileOutputStream(of); } catch (FileNotFoundException e) { Logger.D(TAG, "Can't open file " + of.getAbsolutePath() + ", check next path"); continue; } Logger.D(TAG, "File " + of.getAbsolutePath() + " succesfully opened for write, start download app"); tmpFile = of; break; } */ tmpFile = ctx.getFileStreamPath(UUID.randomUUID().toString() + ".apk"); os = ctx.openFileOutput(tmpFile.getName(), Context.MODE_WORLD_READABLE); Logger.D(TAG, "Download " + url + " to " + tmpFile.getAbsolutePath() + "..."); URL u = new URL(url); URLConnection conn = u.openConnection(); int totalBytes = -1; if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; totalBytes = httpConn.getContentLength(); } is = conn.getInputStream(); int downloaded = 0; updateDownloadNotification(url, totalBytes, downloaded); long prevProgress = 0; byte[] buf = new byte[65536]; for (;;) { if (thisThread.isInterrupted()) { tmpFile.delete(); Logger.D(TAG, "Download of " + url + " was canceled"); return null; } int nread = is.read(buf); if (nread == -1) break; //Logger.D(TAG, "Downloading " + url + ": got " + nread + " bytes..."); os.write(buf, 0, nread); downloaded += nread; if (totalBytes > 0) { // Update progress view only if current progress is greater than // previous by more than 10%. Otherwise, if update it very frequently, // user will no have chance to click on notification view and cancel if need long progress = downloaded * 10 / totalBytes; if (progress > prevProgress) { updateDownloadNotification(url, totalBytes, downloaded); prevProgress = progress; } } } Logger.D(TAG, "File stored to " + tmpFile.getAbsolutePath()); return tmpFile; } catch (IOException e) { if (tmpFile != null) tmpFile.delete(); throw e; } finally { try { if (is != null) is.close(); } catch (IOException e) { } try { if (os != null) os.close(); } catch (IOException e) { } mNM.cancel(DOWNLOAD_PACKAGE_ID); ctx.unregisterReceiver(downloadReceiver); } }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void sendTestNotification(Context context) { if (!TEST_NOTIFICATION) { return;/*from www. ja va 2s . com*/ } 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:csh.cryptonite.Cryptonite.java
public static void setupReadDirs(boolean external, Context context) { if (DirectorySettings.INSTANCE.openDir != null) { Cryptonite.deleteDir(DirectorySettings.INSTANCE.openDir); }/*from www . j a v a 2 s .c om*/ if (DirectorySettings.INSTANCE.readDir != null) { Cryptonite.deleteDir(DirectorySettings.INSTANCE.readDir); } if (external && Cryptonite.externalStorageIsWritable()) { context.getExternalCacheDir().mkdirs(); DirectorySettings.INSTANCE.openDir = new File( context.getExternalCacheDir().getPath() + "/" + DirectorySettings.OPENPNT); DirectorySettings.INSTANCE.readDir = new File( context.getExternalCacheDir().getPath() + "/" + DirectorySettings.READPNT); DirectorySettings.INSTANCE.openDir.mkdirs(); DirectorySettings.INSTANCE.readDir.mkdirs(); } else { DirectorySettings.INSTANCE.openDir = context.getDir(DirectorySettings.OPENPNT, Context.MODE_PRIVATE); DirectorySettings.INSTANCE.readDir = context.getDir(DirectorySettings.READPNT, Context.MODE_WORLD_READABLE); } }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void sendTestNotification(Context context) { if (!TEST_NOTIFICATION) { return;/*from w ww. j a va2s .c om*/ } 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:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Saves data to the application internal folder. * /*w w w . ja v a2 s. c o m*/ * @param context * @param fileName * @param data * @throws Exception */ public static synchronized void storage_storeDataInInternalStorage(Context context, String fileName, byte[] data) throws Exception { try { /* We have to use the openFileOutput()-method * the ActivityContext provides, to * protect your file from others and * This is done for security-reasons. * We chose MODE_WORLD_READABLE, because * we have nothing to hide in our file */ FileOutputStream fOut = context.openFileOutput(fileName, Context.MODE_WORLD_READABLE); // Write the string to the file fOut.write(data); /* ensure that everything is really written out and close */ fOut.flush(); fOut.close(); } catch (Exception e) { throw new Exception("Error saving data to '" + fileName + "' (internal storage) : " + e.getMessage(), e); } }
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 {/* www. jav a2s . co 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 {/*from ww w. j av a 2 s . c o m*/ 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); }