[APP]APK Exporter app - Android Apps and Games

Hello there,
This is my first post here.
I made an application (not a unique one) that helps users to get APk of installed apps and share them also.
As I can't share the link because I'm a fresh new user, this is the id of the app on google play com.game.ammar.apkexporter
And here the piece of code I use to get the APK.
Code:
PackageManager packageManager = getActivity().getPackageManager();
int flags = PackageManager.GET_META_DATA|PackageManager.GET_SHARED_LIBRARY_FILES;
ApplicationInfo applicationInfoo = packageManager.getApplicationInfo(data.getPack(), flags);
File folder = new File(Environment.getExternalStorageDirectory().getPath() +"/APKExporter");
if(!folder.exists())folder.mkdir();
folder = new File(folder.getPath() + "/apk");
if(!folder.exists()) folder.mkdir();
apkFile = new File(folder.getPath() + "/" + applicationInfoo.packageName + ".apk");
copy(new File(applicationInfoo.sourceDir), apkFile);
I want to get a feedback for the app and share my work with all of you.

Related

HardSPL CDMA Whitelist Code

Guys,
A buddy of mine modified Fenny's code from IMEI Whitelist GSM Hardspl to work with CDMA. I just need someone to compile code and test.
Code:
Random random = new Random();
string imei = textBox1.Text;
string mid = (random.Next().ToString("X8") + random.Next().ToString("X8")).ToLower();
string hid = random.Next().ToString("X8").ToLower();
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
System.Security.Cryptography.SHA256 hasher = System.Security.Cryptography.SHA256.Create();
string hex = BitConverter.ToString(hasher.ComputeHash(encoding.GetBytes(((mid + hid + imei + "6BRSDB*(LNsa;JN5)"))))).Replace("-", "").ToLower(); ;
string request = ("mid=" + mid + "&hid=" + hid + "&imei=" + imei + "&auth=" + hex + "&v=" + 110);
System.Net.ServicePointManager.Expect100Continue = false;
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://www.htc-unlocks.com/rhodiumw.php");
webRequest.Headers.Clear();
webRequest.KeepAlive = true;
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.UserAgent = "WinHTTP Example/1.0";
System.IO.Stream webResponse = webRequest.GetRequestStream();
System.IO.StreamWriter webResponseSender = new System.IO.StreamWriter(webResponse);
webResponseSender.Write(request);
webResponseSender.Close();
System.Net.HttpWebResponse didI = (System.Net.HttpWebResponse)webRequest.GetResponse();
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(didI.GetResponseStream());
byte[] buffered = binaryReader.ReadBytes(512);
if (encoding.GetString(buffered) == "reject")
label2.Text = "Failed";
else
{
System.IO.File.WriteAllBytes(imei+".txt", buffered);
label2.Text = "Success";
}
OK, I have the code compiled.
run the exe file.
enter your IMEI number (do not include last 01)
you shoud get success and it will create a <IMEI_NUMBER>.txt file
rename <IMEI_NUMBER>.txt to chk.txt and copy to windows folders on your phone
now run hardSPL and enjoy.
note if you get a failed message you either enter the last 01, or enter incorrect IMEI or your phone is already blacklisted and it's to late.
My phone is blacklisted so I can not fully test. please post results.
I also want to thank Fenny for his hard work with his GSM version of the whitelister.
With out his code my buddy would have never been able to rewrite to work for CDMA TP2
hopefully you don't mind, i posted this @ geeks....test should come back soon, i linked this thread .
mr8820 said:
hopefully you don't mind, i posted this @ geeks....test should come back soon, i linked this thread .
Click to expand...
Click to collapse
no not at all post in all related sites are fine.

[Q]Using License Check Ressault

ok so i have added a license check to my app. but the only way i can find of using it is like this.
Code:
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
ConnectivityManager connManager1 = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mMobile = connManager1.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mWifi.isConnected()) {
checkLicense();
} else if (mMobile.isConnected()) {
checkLicense();
}
if i get my app the run the license check with the internet being off it says i need to buy it. so does anyone know a way i can read the ressaults of the file it create to save the ressaults of the license check(the file created is called "com.android.vending.licensing.ServerManagedPolicy.xml", this file is in the "shared_prefs" folder).

[Q]c# / development questions (background-img, checkbox)

Hi
i work on my first app, the info-part is finished. now i want add a simple question/answer-part. the first part with button for answers and questions works fine, but with the checkboxes i have some problems.
i want two or three solutions for one question, wich can be choose if i am click on one of these checkboxes. the answer is showing up in MessageBox and work so far, but the checkbox don't be cleared!?
What i have to do, to clear the checkbox. please help me! i don't know so much about the source-code c#, so every explanation will help me! Thanks!
xaml.cs
Code:
private void checkBox6_Checked(object sender, RoutedEventArgs e)
{
MessageBox.Show("Richtig!");
checkBox6.?? = checkBox6.??;
}
private void checkBox7_Checked(object sender, RoutedEventArgs e)
{
MessageBox.Show("Richtig!");
checkBox7.?? = checkBox7.??;
}
xaml
Code:
<TextBlock Height="73" HorizontalAlignment="Left" Margin="13,489,0,0" Name="DerTextblock13" VerticalAlignment="Top" TextWrapping="Wrap" Width="436" FontSize="22">Question?</TextBlock>
<CheckBox Content="YES" Height="72" HorizontalAlignment="Left" Margin="5,518,0,0" Name="checkBox6" VerticalAlignment="Top" Checked="checkBox6_Checked" />
<CheckBox Content="NO" Height="72" HorizontalAlignment="Right" Margin="0,518,18,0" Name="checkBox7" VerticalAlignment="Top" Checked="checkBox7_Checked" />
Just need to change the IsChecked property.
checkbox6.IsChecked = false;
hi
thanks for your comment.. i have read and search about "checkbox6.IsChecked = false;" and test it, but it doesn't work. i got this error in attached image.. checkbox6 is in content not available, but there is in content the checkbox6 (Name="checkbox6" and Checked="checkBox6_Checked")..
so i still don't know, why i get this error.. sorry for my stupid question..
Control names are case sensitive. It should be checkBox6.IsChecked = false;
oh man, what a stupid error.. thanks, case sensitive was the right keyword!
how can i change background-image for other xaml-site
hi
i don`t want open a new thread, so i ask here.
new problem! how can i change the background-image for an other xaml-site?
i searched a lot and find a lot, but nothing show me exactly how i can realize this.
in the source-code below, you see that i can change the background-image for example on mainpage.xaml.
Now i want integrate in my setting.xaml and settings.xaml.cs the same checkboxes to change the background-image on the mainpage.xaml.
What i have to do? Thanks for help!
xaml.cs
Code:
private void checkBox2_Checked(object sender, RoutedEventArgs e)
{
Uri uriR = new Uri("image/angler.png", UriKind.Relative);
BitmapImage imgSource = new BitmapImage(uriR);
this.imagechange.Source = imgSource;
checkBox1.IsChecked = false;
}
private void checkBox1_Checked(object sender, RoutedEventArgs e)
{
Uri uriR = new Uri("image/new-background.png", UriKind.Relative);
BitmapImage imgSource = new BitmapImage(uriR);
this.imagechange.Source = imgSource;
checkBox2.IsChecked = false;
}
xaml
Code:
<CheckBox Content="Hintergrund" Height="72" Margin="54,-33,0,0" Name="checkBox2" Checked="checkBox2_Checked" Width="163" FontSize="18" />
<CheckBox Content="Hintergrund 2" Height="72" Margin="0,-33,49,0" Name="checkBox1" Checked="checkBox1_Checked" Width="187" FontSize="18" />
Well done very good
Not sure if it's the best way, but one option would be to store the value you want to use in IsolatedStorageSettings. Then, when the page loads, it checks the value in ISS and applies that background (in its OnNavigatedTo event handler is probably best).
GoodDayToDie said:
Not sure if it's the best way, but one option would be to store the value you want to use in IsolatedStorageSettings. Then, when the page loads, it checks the value in ISS and applies that background (in its OnNavigatedTo event handler is probably best).
Click to expand...
Click to collapse
thanks, i have found a code to read an image in IsolatedStorage.. see below..
but i got a error.. i found a example-project, all works fine and i can read a image-file from IsolatedStorage. but in my app it doesn't work and i got these error..
also i had added the namespaces in xaml.cs
using System.IO.IsolatedStorage;
using System.IO;
xaml.cs
xaml-code
Code:
<Image x:Name="imagechange" Margin="30,62,38,204" Stretch="Fill" />
<Button Content="lesen" Height="72" HorizontalAlignment="Left" Margin="269,533,0,0" x:Name="lesen" VerticalAlignment="Top" Width="160" FontSize="19" Click="lesen_Click" />
vs 2010 are showing no faults in debugmodus! But if i click on button "lesen", i got the attached error. Please, where is the fault or what i have to do now?
does anyone has a idea about my described problem. sorry for my stupid questions, but that's all new for me and i want to learn it..
Do you have actual file "logo.jpg" on your ISF? Insert before opening:
if (myIsolatedStorage.FileExists("logo.jpg"))
{
... your code ...
sensboston said:
Do you have actual file "logo.jpg" on your ISF? Insert before opening:
if (myIsolatedStorage.FileExists("logo.jpg"))
{
... your code ...
Click to expand...
Click to collapse
hi
i had added your comment to source-code.. now, nothing happen, if i click on the button for reading the file from isolated storage..
how can i add the file "logo.jpg" to isolated storage?? i thought, i only have to put the file to my current project, like i did it with other images and then i can save or read the file to isolated storage.
I think this must be the fault. How can manage it? thanks..
Code:
private void lesen_Click(object sender, RoutedEventArgs e)
{
BitmapImage bi = new BitmapImage();
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists("logo.jpg"))
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
{
bi.SetSource(fileStream);
this.imagechange.Height = bi.PixelHeight;
this.imagechange.Width = bi.PixelWidth;
}
}
this.imagechange.Source = bi;
}
jayjojayson said:
i had added your code in comment to source-code.. now, nothing happen, if i click on the button for reading the file from isolated storage..
how can i add the file "logo.jpg" to isolated storage??
Click to expand...
Click to collapse
You may try to:
- download image from network and save to isf;
- copy from resource stream to isf;
- manually upload file to the app ISF using ISETool.exe or third-party tool.
jayjojayson said:
i thought, i only have to put the file to my current project, like i did it with other images and then i can save or read the file to isolated storage.
Click to expand...
Click to collapse
Wrong assumption.
P.S. Try this (btw, it's a first google link!): http://technodave.wordpress.com/201...ge-for-local-html-content-on-windows-phone-7/
hi
thanks a lot, it works... the first comment you have written are right..
i only have to save it first to isolated storage, before i can read the file.
thanks for your explanation to add files to ISF.. i have serach for that topic, but found nothing that describe how to added to ISF.. thanks for the link... i will read this in the evening...
now i have to find out, how i can change a image on a other site(xaml). than i can change for example in my setting.xaml the background in the mainpage.xaml
every day i learn new things, that's really exciting...
jayjojayson said:
now i have to find out, how i can change a image on a other site(xaml). than i can change for example in my setting.xaml the background in the mainpage.xaml
Click to expand...
Click to collapse
Sorry, I didn't read the whole thread before answering; seems like you are digging in the wrong direction. You don't need to use ISF (but it was a good practice for you), all you need is just a dynamical binding.
I'm too lazy to type code sample for you but (he-he!), our good friend google.com returned a good link for you http://www.eugenedotnet.com/2011/05...-property-in-silverlight-and-windows-phone-7/
P.S. Experience to use google should be "the must" in developer's experience.
entry Text in new line
Hi
i use google, my best friend, for a lot of my questions. but sometimes i don't know the right searchkeywords to do what i want to do (like image binding).
i have a new small problem. in my app i have 4 textboxes, that i use to write in some data. These 4 textboxes, i write to isolated storage in a textfile and let them summarized showing up in a textblock. This works fine.
Now, if i want write a new entry, these entry is written directly after the first entry.
example like is insert in textblock
Code:
▷Text - Text - Text - Text| ▷Text - Text - Text - Text|
But i want that the entry is written in a new line? How can i do this?
example like i want it
Code:
▷Text - Text - Text - Text|
▷Text - Text - Text - Text|
i know that i can create new lines with \n , \r\n and Environment.NewLine.
Code:
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
//create new file
using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("fangbuch.txt", FileMode.Create, FileAccess.Write, myIsolatedStorage)))
{
string someTextData = text.Text + "▷" + datum.Text + " - " + fisch.Text + " - " + größe.Text + "cm" + " - " + gewicht.Text + "Kg" + " | " + "\r\n";
writeFile.WriteLine(someTextData);
writeFile.Close();
}
if i use one of the elements to create a new line, like is showing in code above, the new (second) entry overwrite the first entry. What can i do now? thanks for your help.
You're using FileMode.Create, which will overwrite an existing file. You need to either use FileMode.OpenOrCreate and then seek to the end of the file, or you need to use FileMode.Append (this is the preferred approach).
Additionally, the StreamWriter.WriteFile function automatically appends a newline for you. There's no need to have them manually placed at the end of your text string.
http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx

[Q] Load SQLite DB

I have SQLite DB file. I copy him to StorageFile and open it by SQLite
Code:
...............................
using SQLiteClient;
using Community.CsharpSqlite;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
// Конструктор
private string fileName = "DB";
public MainPage()
{
InitializeComponent();
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
System.IO.Stream src = Application.GetResourceStream(new Uri(fileName, UriKind.Relative)).Stream;
IsolatedStorageFileStream dest = new IsolatedStorageFileStream(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, store);
src.Position = 0;
CopyStream(src, dest);
dest.Flush();
dest.Close();
src.Close();
dest.Dispose();
IsolatedStorageFile tmp= IsolatedStorageFile.GetUserStoreForApplication();
if (!tmp.FileExists(fileName))
{
return;
}
SQLiteConnection db = new SQLiteConnection(fileName);
try
{
db.Open();
SQLiteCommand cmd = db.CreateCommand("SELECT * FROM table");
var lst = cmd.ExecuteQuery<Test>();
ApplicationTitle.Text = "Selected " + lst.ToList().Count + " items\r\nTime ";
}
catch (SQLiteException ex)
{
ApplicationTitle.Text = "Error: " + ex.Message;
}
}
private static void CopyStream(System.IO.Stream input, IsolatedStorageFileStream output)
{
byte[] buffer = new byte[32768];
long TempPos = input.Position;
int readCount;
do
{
readCount = input.Read(buffer, 0, buffer.Length);
if (readCount > 0)
{
output.Write(buffer, 0, readCount);
}
} while (readCount > 0);
input.Position = TempPos;
}
}
public class Test
{
public Test()
{
}
int _id;
public int id
{
get { return _id; }
set { _id = value; }
}
}
}
Result : ApplicationTitle = unable to opendatabase file.
Why? Plz help.
Probably because you doing something wrong, for example, opening SQLiteConnection
Seems like correct syntax should be
Code:
new SqliteConnection("Version=3,uri=file:db")
Download and try source code from http://wp7sqlite.codeplex.com/SourceControl/list/changesets#
error "Couldn't open database file version=3,urlB"
file DB i created from command "backup DB File". It's right?
I have no idea what kind of file do you have. I just downloaded and ran example from sources mentioned above and it works fine (but with few assertions). BTW you should have a complete source code of SQLite, just debug into SQLite procedures and check what's wrong.
Example work fine. I want read database from project file (Content).He isn't located in StorageFile. I use him after i'm saving myfile to StorageFile .
evgen_wp said:
Example work fine. I want read database from project file (Content).He isn't located in StorageFile. I use him after i'm saving myfile to StorageFile .
Click to expand...
Click to collapse
I already understood you. Add your code (to save database file from resource stream to isf) to example, and test conn.Open() call using F11 (Step Into). You'll see what's wrong. I don't have your database file and have no idea what did you put inside
File did not have time to create. It is ... work now.he can open empty file but can't open file with data
P.S. I use Sqlite Client for Windows Phone from http://sqlitewindowsphone.codeplex.com/
Why don't you use another codeplex project I've posted above? It works fine for me (tested because of your question).
P.S. Don't forget to push "Thanks" button. It's not a paid Microsoft customer service and I'm not your support guy.

[HOWTO] Write to media card (secondary storage) from an app under Android 4.4 KitKat

In Android 4.4 KitKat, Google/AOSP made the following change to the API specification, much to the detriment of app developers and users:
"The WRITE_EXTERNAL_STORAGE permission must only grant write access to the primary external storage on a device. Apps must not be allowed to write to secondary external storage devices, except in their package-specific directories as allowed by synthesized permissions."
Click to expand...
Click to collapse
Source: http://source.android.com/devices/tech/storage/index.html
You can read my rather unhappy write-up about it here: https://plus.google.com/108338299717386673901/posts/gjnmuaDM8sn
This only applies to dual-storage devices, i.e., devices with a user-writable internal flash storage AND a removable SD card. But if your device has both, as of Android 4.4, apps will no longer be able to write arbitrarily to the "secondary" storage (the SD card).
There is however still an API exposed that will allow you to write to secondary storage, notably the media content provider. This is far from an ideal solution, and I imagine that someday it will not be possible.
I've written a tiny bit of code to let your applications continue to work with files on the SD card using the media content provider. This code should only be used to write to the secondary storage on Android 4.4+ devices if all else fails. I would strongly recommend that you NEVER rely on this code. This code DOES NOT use root access.
The class:
Code:
/*
* Copyright (C) 2014 NextApp, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package nextapp.mediafile;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.MediaStore;
/**
* Wrapper for manipulating files via the Android Media Content Provider. As of Android 4.4 KitKat, applications can no longer write
* to the "secondary storage" of a device. Write operations using the java.io.File API will thus fail. This class restores access to
* those write operations by way of the Media Content Provider.
*
* Note that this class relies on the internal operational characteristics of the media content provider API, and as such is not
* guaranteed to be future-proof. Then again, we did all think the java.io.File API was going to be future-proof for media card
* access, so all bets are off.
*
* If you're forced to use this class, it's because Google/AOSP made a very poor API decision in Android 4.4 KitKat.
* Read more at https://plus.google.com/+TodLiebeck/posts/gjnmuaDM8sn
*
* Your application must declare the permission "android.permission.WRITE_EXTERNAL_STORAGE".
*/
public class MediaFile {
private final File file;
private final ContentResolver contentResolver;
private final Uri filesUri;
private final Uri imagesUri;
public MediaFile(ContentResolver contentResolver, File file) {
this.file = file;
this.contentResolver = contentResolver;
filesUri = MediaStore.Files.getContentUri("external");
imagesUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
}
/**
* Deletes the file. Returns true if the file has been successfully deleted or otherwise does not exist. This operation is not
* recursive.
*/
public boolean delete()
throws IOException {
if (!file.exists()) {
return true;
}
boolean directory = file.isDirectory();
if (directory) {
// Verify directory does not contain any files/directories within it.
String[] files = file.list();
if (files != null && files.length > 0) {
return false;
}
}
String where = MediaStore.MediaColumns.DATA + "=?";
String[] selectionArgs = new String[] { file.getAbsolutePath() };
// Delete the entry from the media database. This will actually delete media files (images, audio, and video).
contentResolver.delete(filesUri, where, selectionArgs);
if (file.exists()) {
// If the file is not a media file, create a new entry suggesting that this location is an image, even
// though it is not.
ContentValues values = new ContentValues();
values.put(MediaStore.Files.FileColumns.DATA, file.getAbsolutePath());
contentResolver.insert(imagesUri, values);
// Delete the created entry, such that content provider will delete the file.
contentResolver.delete(filesUri, where, selectionArgs);
}
return !file.exists();
}
public File getFile() {
return file;
}
/**
* Creates a new directory. Returns true if the directory was successfully created or exists.
*/
public boolean mkdir()
throws IOException {
if (file.exists()) {
return file.isDirectory();
}
ContentValues values;
Uri uri;
// Create a media database entry for the directory. This step will not actually cause the directory to be created.
values = new ContentValues();
values.put(MediaStore.Files.FileColumns.DATA, file.getAbsolutePath());
contentResolver.insert(filesUri, values);
// Create an entry for a temporary image file within the created directory.
// This step actually causes the creation of the directory.
values = new ContentValues();
values.put(MediaStore.Files.FileColumns.DATA, file.getAbsolutePath() + "/temp.jpg");
uri = contentResolver.insert(imagesUri, values);
// Delete the temporary entry.
contentResolver.delete(uri, null, null);
return file.exists();
}
/**
* Returns an OutputStream to write to the file. The file will be truncated immediately.
*/
public OutputStream write()
throws IOException {
if (file.exists() && file.isDirectory()) {
throw new IOException("File exists and is a directory.");
}
// Delete any existing entry from the media database.
// This may also delete the file (for media types), but that is irrelevant as it will be truncated momentarily in any case.
String where = MediaStore.MediaColumns.DATA + "=?";
String[] selectionArgs = new String[] { file.getAbsolutePath() };
contentResolver.delete(filesUri, where, selectionArgs);
ContentValues values = new ContentValues();
values.put(MediaStore.Files.FileColumns.DATA, file.getAbsolutePath());
Uri uri = contentResolver.insert(filesUri, values);
if (uri == null) {
// Should not occur.
throw new IOException("Internal error.");
}
return contentResolver.openOutputStream(uri);
}
}
Source download (or cut/paste the above): http://android.nextapp.com/content/mediawrite/v1/MediaFile.java
Eclipse project with test app: http://android.nextapp.com/content/mediawrite/v1/MediaWrite.zip
APK of test app: http://android.nextapp.com/content/mediawrite/v1/MediaWrite.apk
The test project is currently configured to target the path /storage/extSdCard/MediaWriteTest (this is correct for a Note3, at least on 4.3...make sure you don't have anything there). Edit MainActivity.java in the Eclipse project to change it.
And again, let me stress that the above code might not work in the future should Google dislike it. I wouldn't recommend that the average app developer make use of this code, but if you're writing a file manager (or something else that competes with any of my other apps) , it might be useful to you. And actually at the time of writing, this functionality is NOT in FX File Explorer or WebSharing.
Follow up:
My understanding is that creating and deleting files with this method does work on Android 4.4, but making new directories does not.
Creating directories does work on Android 4.3 (e.g. Google Play Edition) devices that have crippled secondary storage, so that mkdir() method will be useful for all five people who own GPE devices who are still using 4.3.
Too good to be true!
Wow! This is perfect..
This issue has been resolved in another thread using a much simpler method...
Sent from my GT-I9505 using Tapatalk
AMoosa said:
This issue has been resolved in another thread using a much simpler method...
Sent from my GT-I9505 using Tapatalk
Click to expand...
Click to collapse
If that solution is for non-root app developers, can you provide a link?
Bear in mind this solution is for app developers writing apps for users who may be on stock firmware without root access. I'm familiar with the proper solution for rooted users, where media_rw is added for the WRITE_EXTERNAL_STORAGE permission in /etc/permissions/platform.xml.
tliebeck said:
If that solution is for non-root app developers, can you provide a link?
Bear in mind this solution is for app developers writing apps for users who may be on stock firmware without root access. I'm familiar with the proper solution for rooted users, where media_rw is added for the WRITE_EXTERNAL_STORAGE permission in /etc/permissions/platform.xml.
Click to expand...
Click to collapse
Root solution... Possible to grant WRITE_MEDIA_STORAGE via pm grant in shell (non root via adb shell?)? Samsung File Manager uses it and it can access to extsdcard. Better than modifying system file.
But I agree that we need Fixer app for that (to fix things in etc/permissions/platform.xml)
I did this method when we first got kitkat a while back http://forum.xda-developers.com/showthread.php?t=2524277
But rooted devices. Good job bro
tliebeck said:
If that solution is for non-root app developers, can you provide a link?
Bear in mind this solution is for app developers writing apps for users who may be on stock firmware without root access. I'm familiar with the proper solution for rooted users, where media_rw is added for the WRITE_EXTERNAL_STORAGE permission in /etc/permissions/platform.xml.
Click to expand...
Click to collapse
Hi. Yes it's the one you have cited. Isn't everyone on xda rooted these days? Lol.
Sent from my GT-I9505 using Tapatalk
pyler said:
Root solution... Possible to grant WRITE_MEDIA_STORAGE via pm grant in shell (non root via adb shell?)? Samsung File Manager uses it and it can access to extsdcard. Better than modifying system file.
But I agree that we need Fixer app for that (to fix things in etc/permissions/platform.xml)
Click to expand...
Click to collapse
The Samsung file manager declares it in its manifest, and I believe it's available to any system app that does so. I'm not sure on the method by which these permissions are granted (i.e., if it's based on having a certain signature, or if just being in /system is enough). I didn't think there was a means to grant it to any non-system app without using root though.
I did try just try declaring that in the manifest, and it pm grant returns the following (for shell and root):
Operation not allowed: java.lang.SecurityException: Permission android.permission.WRITE_MEDIA_STORAGE is not a changeable permission type
Click to expand...
Click to collapse
Thanks for the suggestion though, was worth a try.
AMoosa said:
Hi. Yes it's the one you have cited. Isn't everyone on xda rooted these days? Lol.
Sent from my GT-I9505 using Tapatalk
Click to expand...
Click to collapse
Yeah, this certainly isn't going to be *personally* useful to anyone here...just posted it for app devs catering to users on non-rooted stock stuff.
tliebeck said:
Yeah, this certainly isn't going to be *personally* useful to anyone here...just posted it for app devs catering to users on non-rooted stock stuff.
Click to expand...
Click to collapse
I have a question, if I install the kitkat 4.4.2 update for sprint can I then install apk or is there a diffrent way also im not rooted. Cause this is the only thing stopping me from installing the update.
dadda said:
I have a question, if I install the kitkat 4.4.2 update for sprint can I then install apk or is there a diffrent way also im not rooted. Cause this is the only thing stopping me from installing the update.
Click to expand...
Click to collapse
Would not recommend it, this is still not confirmed to work, and only affects applications that implement it. Only real solution is still rooting.
Thanks, I'm still debating on rooting my phone cause of my evo 3D camera stop working.
Apparently the latest update of ES File Explorer should give write access to the external SD card without root, here's the changelog:
Code:
V3.1.1
-Samsung external card write issue on Android 4.4 Kitkat
-Multi-thread download & copy setting
-Video/audio thumbnails
-Download Facebook video when playing(use FB link in homepage)
It would be interesting to know the hack the app used to write and delete files there!
virtualdj said:
Apparently the latest update of ES File Explorer should give write access to the external SD card without root, here's the changelog:
Code:
V3.1.1
-Samsung external card write issue on Android 4.4 Kitkat
-Multi-thread download & copy setting
-Video/audio thumbnails
-Download Facebook video when playing(use FB link in homepage)
It would be interesting to know the hack the app used to write and delete files there!
Click to expand...
Click to collapse
The above code should work for creating and deleting files.
My question would be whether or not they are able to create new folders? If they can, they've found a new workaround.
Base directory in this app is storage/extSdCard/WriteMediaTest
My base directory is storage/sdcard1/WriteMediaTest
Can you change this?
Wysłane z mojego GT-P3100 przy użyciu Tapatalka
tliebeck said:
The above code should work for creating and deleting files.
My question would be whether or not they are able to create new folders? If they can, they've found a new workaround.
Click to expand...
Click to collapse
ES Explorer can create directory on ext sdcard without root.
Anyone get updated with how to do that?
jimmod said:
ES Explorer can create directory on ext sdcard without root.
Anyone get updated with how to do that?
Click to expand...
Click to collapse
I just got 4.4.2 on m G Tab 8.3. I can't do a File.mkdir(), but I could do it from the command line. I could also do a cp. Maybe they are doing a Runtime.exec()?
Update. Just tried that. Did not work, permission denied. Weird that that shell user can, but an app user can't.
dburckh said:
I just got 4.4.2 on m G Tab 8.3. I can't do a File.mkdir(), but I could do it from the command line. I could also do a cp. Maybe they are doing a Runtime.exec()?
Update. Just tried that. Did not work, permission denied. Weird that that shell user can, but an app user can't.
Click to expand...
Click to collapse
Yes, adb shell (shell user) is able to create folder.
But if using terminal emulator app it permission denied.
Most likely shell user have write permission. But to switch to shell user from app will need root access.
Sorry for not updating this thread promptly with this information, but there is now a 4.4 folder creation workaround, courtesy of the developer of X-plore File Manager. Works on Samsung devices, but apparently doesn't on Sony or HTC stuff. Not sure why this is the case.
I haven't had time to update the original standalone sample app/project, but here's the complete workaround class straight out of FX beta. This code is designed to be built against Android 2.1 (API level 7), hence the use of reflection. It's using the media API to generate album art for an MP3 track and place it in the folder you want created. Tiny MP3 file is attached, place that in /res/raw.
Code:
package nextapp.maui.io;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import nextapp.maui.AndroidEnvironment;
import nextapp.maui.Maui;
import nextapp.maui.R;
import nextapp.maui.storage.ContentUriUtil;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.util.Log;
/**
* Wrapper for manipulating files via the Android Media Content Provider. As of Android 4.4 KitKat, applications can no longer write
* to the "secondary storage" of a device. Write operations using the java.io.File API will thus fail. This class restores access to
* those write operations by way of the Media Content Provider.
*
* Note that this class relies on the internal operational characteristics of the media content provider API, and as such is not
* guaranteed to be future-proof. Then again, we did all think the java.io.File API was going to be future-proof for media card
* access, so all bets are off.
*
* If you're forced to use this class, it's because Google/AOSP made a very poor API decision in Android 4.4 KitKat.
* Read more at https://plus.google.com/+TodLiebeck/posts/gjnmuaDM8sn
*
* Your application must declare the permission "android.permission.WRITE_EXTERNAL_STORAGE".
*/
public class MediaFile {
private static final String NO_MEDIA = ".nomedia";
private static final String ALBUM_ART_URI = "content://media/external/audio/albumart";
private static final String[] ALBUM_PROJECTION = { BaseColumns._ID, MediaStore.Audio.AlbumColumns.ALBUM_ID, "media_type" };
private static File getExternalFilesDir(Context context) {
if (AndroidEnvironment.SDK < AndroidEnvironment.FROYO) {
return null;
}
try {
Method method = Context.class.getMethod("getExternalFilesDir", String.class);
return (File) method.invoke(context, (String) null);
} catch (SecurityException ex) {
Log.d(Maui.LOG_TAG, "Unexpected reflection error.", ex);
return null;
} catch (NoSuchMethodException ex) {
Log.d(Maui.LOG_TAG, "Unexpected reflection error.", ex);
return null;
} catch (IllegalArgumentException ex) {
Log.d(Maui.LOG_TAG, "Unexpected reflection error.", ex);
return null;
} catch (IllegalAccessException ex) {
Log.d(Maui.LOG_TAG, "Unexpected reflection error.", ex);
return null;
} catch (InvocationTargetException ex) {
Log.d(Maui.LOG_TAG, "Unexpected reflection error.", ex);
return null;
}
}
public static boolean SUPPORTED = ContentUriUtil.FILES_URI != null;
private final File file;
private final Context context;
private final ContentResolver contentResolver;
public MediaFile(Context context, File file) {
this.file = file;
this.context = context;
contentResolver = context.getContentResolver();
}
/**
* Deletes the file. Returns true if the file has been successfully deleted or otherwise does not exist. This operation is not
* recursive.
*/
public boolean delete()
throws IOException {
if (!SUPPORTED) {
throw new IOException("MediaFile API not supported by device.");
}
if (!file.exists()) {
return true;
}
boolean directory = file.isDirectory();
if (directory) {
// Verify directory does not contain any files/directories within it.
String[] files = file.list();
if (files != null && files.length > 0) {
return false;
}
}
String where = MediaStore.MediaColumns.DATA + "=?";
String[] selectionArgs = new String[] { file.getAbsolutePath() };
// Delete the entry from the media database. This will actually delete media files (images, audio, and video).
contentResolver.delete(ContentUriUtil.FILES_URI, where, selectionArgs);
if (file.exists()) {
// If the file is not a media file, create a new entry suggesting that this location is an image, even
// though it is not.
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
// Delete the created entry, such that content provider will delete the file.
contentResolver.delete(ContentUriUtil.FILES_URI, where, selectionArgs);
}
return !file.exists();
}
public File getFile() {
return file;
}
private int getTemporaryAlbumId() {
final File temporaryTrack;
try {
temporaryTrack = installTemporaryTrack();
} catch (IOException ex) {
return 0;
}
final String[] selectionArgs = { temporaryTrack.getAbsolutePath() };
Cursor cursor = contentResolver.query(ContentUriUtil.FILES_URI, ALBUM_PROJECTION, MediaStore.MediaColumns.DATA + "=?",
selectionArgs, null);
if (cursor == null || !cursor.moveToFirst()) {
if (cursor != null) {
cursor.close();
cursor = null;
}
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, temporaryTrack.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "{MediaWrite Workaround}");
values.put(MediaStore.MediaColumns.SIZE, temporaryTrack.length());
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg");
values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, true);
contentResolver.insert(ContentUriUtil.FILES_URI, values);
}
cursor = contentResolver.query(ContentUriUtil.FILES_URI, ALBUM_PROJECTION, MediaStore.MediaColumns.DATA + "=?",
selectionArgs, null);
if (cursor == null) {
return 0;
}
if (!cursor.moveToFirst()) {
cursor.close();
return 0;
}
int id = cursor.getInt(0);
int albumId = cursor.getInt(1);
int mediaType = cursor.getInt(2);
cursor.close();
ContentValues values = new ContentValues();
boolean updateRequired = false;
if (albumId == 0) {
values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, 13371337);
updateRequired = true;
}
if (mediaType != 2) {
values.put("media_type", 2);
updateRequired = true;
}
if (updateRequired) {
contentResolver.update(ContentUriUtil.FILES_URI, values, BaseColumns._ID + "=" + id, null);
}
cursor = contentResolver.query(ContentUriUtil.FILES_URI, ALBUM_PROJECTION, MediaStore.MediaColumns.DATA + "=?",
selectionArgs, null);
if (cursor == null) {
return 0;
}
try {
if (!cursor.moveToFirst()) {
return 0;
}
return cursor.getInt(1);
} finally {
cursor.close();
}
}
private File installTemporaryTrack()
throws IOException {
File externalFilesDir = getExternalFilesDir(context);
if (externalFilesDir == null) {
return null;
}
File temporaryTrack = new File(externalFilesDir, "temptrack.mp3");
if (!temporaryTrack.exists()) {
InputStream in = null;
OutputStream out = null;
try {
in = context.getResources().openRawResource(R.raw.temptrack);
out = new FileOutputStream(temporaryTrack);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
return null;
}
}
if (out != null) {
try {
out.close();
} catch (IOException ex) {
return null;
}
}
}
}
return temporaryTrack;
}
/**
* Creates a new directory. Returns true if the directory was successfully created or exists.
*/
public boolean mkdir()
throws IOException {
if (file.exists()) {
return file.isDirectory();
}
File tmpFile = new File(file, ".MediaWriteTemp");
int albumId = getTemporaryAlbumId();
if (albumId == 0) {
throw new IOException("Fail");
}
Uri albumUri = Uri.parse(ALBUM_ART_URI + '/' + albumId);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, tmpFile.getAbsolutePath());
if (contentResolver.update(albumUri, values, null, null) == 0) {
values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, albumId);
contentResolver.insert(Uri.parse(ALBUM_ART_URI), values);
}
try {
ParcelFileDescriptor fd = contentResolver.openFileDescriptor(albumUri, "r");
fd.close();
} finally {
MediaFile tmpMediaFile = new MediaFile(context, tmpFile);
tmpMediaFile.delete();
}
return file.exists();
}
/**
* Returns an OutputStream to write to the file. The file will be truncated immediately.
*/
public OutputStream write(long size)
throws IOException {
if (!SUPPORTED) {
throw new IOException("MediaFile API not supported by device.");
}
if (NO_MEDIA.equals(file.getName().trim())) {
throw new IOException("Unable to create .nomedia file via media content provider API.");
}
if (file.exists() && file.isDirectory()) {
throw new IOException("File exists and is a directory.");
}
// Delete any existing entry from the media database.
// This may also delete the file (for media types), but that is irrelevant as it will be truncated momentarily in any case.
String where = MediaStore.MediaColumns.DATA + "=?";
String[] selectionArgs = new String[] { file.getAbsolutePath() };
contentResolver.delete(ContentUriUtil.FILES_URI, where, selectionArgs);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
values.put(MediaStore.MediaColumns.SIZE, size);
Uri uri = contentResolver.insert(ContentUriUtil.FILES_URI, values);
if (uri == null) {
// Should not occur.
throw new IOException("Internal error.");
}
return contentResolver.openOutputStream(uri);
}
}

Categories

Resources