View attachment 5209541
What is Share Engine
As a cross-device file transfer solution, Huawei Share uses Bluetooth to discover nearby devices and authenticate connections, then sets up peer-to-peer Wi-Fi channels, so as to allow file transfers between phones, PCs, and other devices. It delivers stable file transfer speeds that can exceed 80 Mbps if the third-party device and environment allow. Developers can use Huawei Share features using Share Engine.
The Huawei Share capabilities are sealed deep in the package, then presented in the form of a simplified engine for developers to integrate with apps and smart devices. By integrating these capabilities, PCs, printers, cameras, and other devices can easily share files with each other.
Three SDK development packages are offered to allow quick integration for Android, Linux, and Windows based apps and devices.
Working Principles
Huawei Share uses Bluetooth to discover nearby devices and authenticate connections, then sets up peer-to-peer Wi-Fi channels, so as to allow file transfers between phones, PCs, and other devices.
View attachment 5209543
To ensure user experience, Huawei Share uses reliable core technologies in each phase of file transfer.
Devices are detected using in-house bidirectional device discovery technology, without sacrificing the battery or security
Connection authentication using in-house developed password authenticated key exchange (PAKE) technology
File transfer using high-speed point-to-point transmission technologies, including Huawei-developed channel capability negotiation and actual channel adjustment
For more information you can follow this link.
Let’s get into codding.
Requirements
For development, we need Android Studio V3.0.1 or later.
EMUI 10.0 or later and API level 26 or later needed for Huawei phone.
Development
1 - First we need to add this permission to AndroidManifest.xml. So that we can ask user for our app to access files.
XML:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
2 - After let’s shape activity_main.xml as bellow. Thus we have one EditText for getting input and three Button in UI for using Share Engine’s features.
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/inputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:hint="@string/hint"
tools:ignore="Autofill,TextFields" />
<Button
android:id="@+id/sendTextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="sendText"
android:text="@string/btn1"
android:textAllCaps="false" />
<Button
android:id="@+id/sendFileButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="sendFile"
android:text="@string/btn2"
android:textAllCaps="false" />
<Button
android:id="@+id/sendFilesButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="sendMultipleFiles"
android:text="@string/btn3"
android:textAllCaps="false" />
</LinearLayout>
3 - By adding the following to strings.xml, we create button and alert texts.
XML:
<string name="btn1">Send text</string>
<string name="btn2">Send single file</string>
<string name="btn3">Send multiple files</string>
<string name="hint">Write something to send</string>
<string name="errorToast">Please write something before sending!</string>
4 - Later, let’s shape the MainActivity.java class. First of all, to provide access to files on the phone, we need to request permission from the user using the onResume method.
Java:
@Override
protected void onResume() {
super.onResume();
checkPermission();
}
private void checkPermission() {
if (checkSelfPermission(READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
String[] permissions = {READ_EXTERNAL_STORAGE};
requestPermissions(permissions, 0);
}
}
5 - Let’s initialize these parameters for later uses and call this function in onCreate method.
Java:
EditText input;
PackageManager manager;
private void initApp(){
input = findViewById(R.id.inputEditText);
manager = getApplicationContext().getPackageManager();
}
6 - We’re going to create Intent with the same structure over and over again, so let’s simply create a function and get rid of the repeated codes.
Java:
private Intent createNewIntent(String action){
Intent intent = new Intent(action);
intent.setType("*");
intent.setPackage("com.huawei.android.instantshare");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
We don’t need an SDK to transfer files between Huawei phones using the Share Engine, instead we can easily transfer files by naming the package “com.huawei.android.instantshare” to Intent as you see above.
7 - Let’s create the onClick method of sendTextButton to send text with Share Engine.
Java:
public void sendText(View v) {
String myInput = input.getText().toString();
if (myInput.equals("")){
Toast.makeText(getApplicationContext(), R.string.errorToast, Toast.LENGTH_SHORT).show();
return;
}
Intent intent = CreateNewIntent(Intent.ACTION_SEND);
List<ResolveInfo> info = manager.queryIntentActivities(intent, 0);
if (info.size() == 0) {
Log.d("Share", "share via intent not supported");
} else {
intent.putExtra(Intent.EXTRA_TEXT, myInput);
getApplicationContext().startActivity(intent);
}
}
8 - Let’s edit the onActivityResult method to get the file/s we choose from the file manager to send it with the Share Engine.
Java:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && data != null) {
ArrayList<Uri> uris = new ArrayList<>();
Uri uri;
if (data.getClipData() != null) {
// Multiple files picked
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
uri = data.getClipData().getItemAt(i).getUri();
uris.add(uri);
}
} else {
// Single file picked
uri = data.getData();
uris.add(uri);
}
handleSendFile(uris);
}
}
With handleSendFile method we can perform single or multiple file sending.
Java:
private void handleSendFile(ArrayList<Uri> uris) {
if (uris.isEmpty()) {
return;
}
Intent intent;
if (uris.size() == 1) {
// Sharing a file
intent = CreateNewIntent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
} else {
// Sharing multiple files
intent = CreateNewIntent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
}
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> info = manager.queryIntentActivities(intent, 0);
if (info.size() == 0) {
Log.d("Share", "share via intent not supported");
} else {
getApplicationContext().startActivity(intent);
}
}
9 - Finally, let’s edit the onClick methods of file sending buttons.
Java:
public void sendFile(View v) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(i, 10);
}
public void sendMultipleFiles(View v) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
i.setType("*/*");
startActivityForResult(i, 10);
}
We’ve prepared all the structures we need to create, so let’s see the output.
Text Sharing:
View attachment 5209563
Single File Sharing:
View attachment 5209565
Multiple File Sharing:
View attachment 5209567
With this guide, you can easily understand and integrate Share Engine to transfer file/s and text with your app.
For more information: https://developer.huawei.com/consumer/en/share-kit/
I'm not a coder and to old to learn. It is and will remain all Greek to me.
namitutonka said:
I'm not a coder and to old to learn. It is and will remain all Greek to me.
Click to expand...
Click to collapse
If you read it and follow as per instruction, its pretty simple
Dope
Wow! So nice i never think i wanna know about this thing...
Very nice and useful.
Related
Hey Guys!
I'm sitting in front of an XML-Problem for five days now and really don't know what's to do. Expect of asking you.
I want to write a small shopping list application that manages the data in an XML-File looking like that:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Items>
<Item>
<Name>Bananas</Name>
<Store>supermarket</Store>
<Repeat>true</Repeat>
</Item>
<Item>
<Name>LG E900 Optimus 7</Name>
<Store>superhandy</Store>
<Repeat>false</Repeat>
</Item>
(...)
I have a ListBox called ItemShowcase that I fill with instances of my ShowCaseEntry-Class
Reading Data from the FIle works perfectly with this code:
Code:
private void updateItemList()
{
// load XML-File
var items = XElement.Load("MissingItems.xml");
foreach (var a in items.Elements())
{
ShowCaseEntry sce = new ShowCaseEntry(a.Element("Name").Value, "Store: " + a.Element("Store").Value, false);
ItemShowcase.Items.Add(sce);
}
}
No Problem until here.
But now I want to add a new Iem to my XML-File.
I have 2 Textfields in what I ask for the Item-Name and Store-Name. Repeat is always true.
I tried that:
Code:
public void addXMLItem(String name, String store, Boolean repeat)
{
// XML-Datei Laden
var items = XDocument.Load("MissingItems.xml");
// neues Item erstellen
XElement newItem = new XElement("Item",
new XElement("Name", name),
new XElement("Store", store),
new XElement("Repeat", repeat) );
// Hinzufügen und spreichern
items.Root.Add(newItem);
FileStream F = new FileStream("MissingItems.xml", FileMode.Open);
items.Save(F);
}
The last line give me the following Error:
Attempt to access the method failed: System.IO.FileStream..ctor(System.String, System.IO.FileMode)
Is anyone here who would help me?
You would save my weekend!
Thank you so much!
Best wishes and greets
Robby
Try something like this:
Code:
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
isoStream = new IsolatedStorageFileStream("MissingItems.xml", FileMode.Create, FileAccess.Write, isoStore);
//Add your xml items here.
xml.Save(isoStream);
isoStream.Close();
First of all thanks for your answer.
Unfortunately I don't really know how to add the XML-Items.
Like this?
Code:
public void addXMLItem(String name, String store, Boolean repeat)
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
isoStream = new IsolatedStorageFileStream("MissingItems.xml", FileMode.Create, FileAccess.Write, isoStore);
//Add your xml items here.
var items = XDocument.Load("MissingItems.xml");
XElement newItem = new XElement("Item",
new XElement("Name", name),
new XElement("Store", store),
new XElement("Repeat", repeat));
items.Root.Add(newItem);
items.Save(isoStream);
isoStream.Close();
}
Another answer would be very nice
Best regards
Robby
I don't have time to test it but hopefully this works for you.
Code:
public void addXMLItem(String name, String store, Boolean repeat)
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
isoStream = new IsolatedStorageFileStream("MissingItems.xml", FileMode.Create, FileAccess.Write, isoStore);
//Add your xml items here.
XDocument items = XDocument.Load(isoStream);
items.Element("Items").Add(
new XElement("Item",
new XElement("Name", name),
new XElement("Store", store),
new XElement("Repeat", repeat)));
items.Save(isoStream);
isoStream.Close();
}
Thank you really much for your engangement, but there is still one problem.
In this line the program throws an XML-Error called "root element is missing":
XDocument items = XDocument.Load(isoStream);
How to explain the Load-Method that "Items" is my root Element?
Greets
Robby
Sorry my code had errors. This is tested and working.
Code:
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
isoStream = new IsolatedStorageFileStream("MissingItems.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
XDocument items = XDocument.Load(isoStream);
isoStream.Close();
items.Element("Items").Add(
new XElement("Item",
new XElement("Name", name),
new XElement("Store", store),
new XElement("Repeat", repeat.ToString())));
isoStream = new IsolatedStorageFileStream("MissingItems.xml", FileMode.Create, FileAccess.Write, isoStore);
items.Save(isoStream);
isoStream.Close();
That code results in this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Items>
<Item>
<Name>Bananas</Name>
<Store>supermarket</Store>
<Repeat>true</Repeat>
</Item>
<Item>
<Name>LG E900 Optimus 7</Name>
<Store>superhandy</Store>
<Repeat>false</Repeat>
</Item>
<Item>
<Name>Test Name</Name>
<Store>Test Store</Store>
<Repeat>False</Repeat>
</Item>
</Items>
I really, really thank you for your anxiety. Thank you for your time, but I just have one more error.
This line throwes an Isolated Storage Exception called "Operation not permitted on IsolatedStorageFileStream.":
isoStream = new IsolatedStorageFileStream("MissingItems.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
You would save my week with a short answer!
Thank you so much till yet
Robby
It sounds like the file stream is already open somewhere else. If you are doing any other reads or writes to the file prior to your addxmlitem method you need to close the stream before calling addxmlitem.
Not really
Sorry, I am sure that I'm annoying but I really need to fix that problem.
My last try to solve ist is to send you the full code:
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;
using System.Xml;
using System.Text;
using System.IO;
using System.IO.IsolatedStorage;
namespace MyShoppingList
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
Item[] itemArray = new Item[2];
CheckBox[] checkBoxArray = new CheckBox[2];
// Set the data context of the listbox control to the sample data
DataContext = App.ViewModel;
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
updateItemList();
}
// Load data for the ViewModel Items
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
}
/// <summary>
/// Adds new Item to the XML-File
/// </summary>
/// <param name="name">Itemname</param>
/// <param name="store">Storename</param>
/// <param name="repeat">Repeat</param>
public void addXMLItem(String name, String store, Boolean repeat)
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
isoStream = new IsolatedStorageFileStream("MissingItems.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
XDocument items = XDocument.Load(isoStream);
isoStream.Close();
items.Element("Items").Add(
new XElement("Item",
new XElement("Name", name),
new XElement("Store", store),
new XElement("Repeat", repeat.ToString())));
isoStream = new IsolatedStorageFileStream("MissingItems.xml", FileMode.Create, FileAccess.Write, isoStore);
items.Save(isoStream);
isoStream.Close();
}
/// <summary>
/// Updates Item List
/// </summary>
private void updateItemList()
{
// XML-Datei Laden
var items = XElement.Load("MissingItems.xml");
foreach (var a in items.Elements())
{
ShowCaseEntry sce = new ShowCaseEntry(a.Element("Name").Value, "Store: " + a.Element("Store").Value, false);
ItemShowcase.Items.Add(sce);
}
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
addXMLItem(tBoxAddItemName.Text, tBoxAddItemStore.Text, false);
//updateItemList();
}
}
}
Can you find any mistakes?
I'm getting desperate...
Thanks a lot for your engagement!
I'n not really sure why that's happening. The only thing I can think of is XElement.Load() is causing the problem so here's how to use XDocument.Load() instead. I really hope this works for you because I'm out of ideas.
Code:
private void updateItemList()
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
isoStream = new IsolatedStorageFileStream("MissingItems.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
XDocument xml = XDocument.Load(isoStream);
var items = from c in xml.Elements("Items").Elements("Item")
select new {
name = c.Element("Name").Value,
store = c.Element("Store").Value,
repeat = c.Element("Repeat").Value
};
foreach (var item in items)
{
ShowCaseEntry sce = new ShowCaseEntry(item.name, "Store: " + item.store, false);
ItemShowcase.Items.Add(sce);
}
isoStream.Close();
}
Same Error on this line:
isoStream = new IsolatedStorageFileStream("MissingItems.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
Operation not permitted on IsolatedStorageFileStream.
I'm at the end of my motivation
I really tried everything, you really tried everything and I cannot find anything helpful to this error message..
Does anyone has an idea?
Does this line works for you?
Big Thanks to Ren13B till yet!
Attached is my working test project. Maybe it will help you.
If you are accessing the Isolated Storage from within a referenced assembly, you will need to access the IsolatedStorageFile for that assembly
Thanks for your reply but how to do that?
hey guys I am getting an error when I am trying to put a twitter feed in my blog app. The error says
“The attachable property ‘ItemTemplate’ was not found in type ‘ListBox’.”
what does this mean. Here is the code that I put in my listbox on the Xaml.
Code:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="132">
<Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
<StackPanel Width="370">
<TextBlock Text="{Binding UserName}" Foreground="#FF2276BB" FontSize="28" />
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" />
<HyperlinkButton Content="{Binding TweetSource}" Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="18" Foreground="#FF999999" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
any help would be appreciated.
Posted XAML code is OK so I can only guess. Probably you've referenced a wrong assembly in your project. Post whole project.
http://blog.objectgraph.com/index.php/2010/03/26/how-to-create-a-twitter-client-on-windows-phone-7/
I am using that site as a guide and putting it in the Wordpress Starter Kit I added a panarama item called Twitter, added a list box and a button and a TextBlock (the text block says OmegaRa) and the buttons says refresh. I am at work currently, so I can't post the rest of my code...
edit: if it matters I named the listbox Twitterfeed, I know I had to alter a couple spots with that to get rid of errors. Plus the original code is for 7.0, in VS2010, I right clicked on the Solution and clicked Upgrade to 7.1...
Seems like this toolkit has a different assemblies for 7.0 and 7.1 (located at sl3-wp & sl4-windowsphone71 folders), check your project references for correct library (7.1).
okay, I am a complete newb when it comes to coding (hence the starter kit and tutorial) how would I go about doing that?
Solution Explorer (on your right) -> References -> click on assembly and check properties. Press Del to remove assembly. Right click and press "Add assembly" from the context menu.
P.S. But before start coding I'm strongly recommend you to RTFM (Read The Following Manual, not the "fu%?ng" one ). Download/buy and read a good manual for Visual Studio and .NET first...
That would probably be a good idea LOL. I just like figuring it out sometimes though, but it would probably go faster if I read something about it first lol.
edit: I will try looking at that when I get home from work and after my daughters birthday dinner lol
Okay, I am home and looking at the references, which assembly would it be?
progress, fixed that part forgot the
Code:
<listbox></listbox>
surrounding it, but when I hit refresh...is doen't get my feed, lol it says something about wordpress starter kit + tweet or something lol.
here is the code for the button
Code:
private void button3_Click(object sender, RoutedEventArgs e)
{
WebClient twitter = new WebClient();
twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + tbUsername.Text));
}
void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
XElement element = XElement.Parse(e.Result);
TwitterFeed.ItemsSource = from tweet in element.Descendants("status")
select new Tweet
{
UserName = tweet.Element("user").Element("screen_name").Value,
Message = tweet.Element("text").Value,
ImageSource = tweet.Element("user").Element("profile_image_url").Value,
TweetSource = FormatTimestamp(tweet.Element("source").Value, tweet.Element("created_at").Value)
};
}
catch (Exception)
{
}
}
public class Tweet
{
public string UserName { get; set; }
public string Message { get; set; }
public string ImageSource { get; set; }
public string TweetSource { get; set; }
}
private string StripHtml(string val)
{
return System.Text.RegularExpressions.Regex.Replace(HttpUtility.HtmlDecode(val), @"<[^>]*>", "");
}
private string DateFormat(string val)
{
string format = "ddd MMM dd HH:mm:ss zzzz yyyy";
DateTime dt = DateTime.ParseExact(val, format, System.Globalization.CultureInfo.InvariantCulture);
return dt.ToString("h:mm tt MMM d");
}
private string FormatTimestamp(string imageSource, string date)
{
return DateFormat(date) + " via " + StripHtml(imageSource);
}
}
}
what the screen says when I hit refresh is WordpressStarterKit.Mainpage+Tweet, and I notice that the button and the Text Block stay on the screen no matter if I pan or not....
PM me your project in archive, I'll correct your errors and send back.
If I change
Code:
twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + tbUsername.Text));
to
Code:
twitter.DownloadStringAsync(new Uri"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=OmegaRa" );
would that fix it? I am just curious to see if I am right..
All issues solved, mod can close thread if they want.
I was wondering, if someone can guide to create a simple app which simplly displays some text on the middle of the screen and 2 buttons (Left and right arrow) to switch to the next or previous text.
I think someone just helped another user who was looking for help for something similar like me but I cannot find it.
Thanks
You can try out this sample code, starting from an empty silverlight project:
In the MainPage.xaml, add the following snippet inside the Grid element named "ContentPanel".
<TextBlock Name="tblkDisplay" Width="360" Height="100" VerticalAlignment="Top" Margin="0,200,0,0" TextAlignment="Center"></TextBlock>
<Button Name="btnBack" Width="160" Height="80" VerticalAlignment="Top" Margin="-200,308,0,0" Click="btnBack_Click">Back</Button>
<Button Name="btnForward" Width="160" Height="80" VerticalAlignment="Top" Margin="200,308,0,0" Click="btnForward_Click">Forward</Button>
This markup adds a TextBlock, and Forward and Back buttons to the page.
In the in the code-behind (MainPage.xaml.cs), use the following code:
Code:
private int _displayIndex; //position in list of text items to display
private List<string> _textItems; //List of text items to display
// Constructor
public MainPage()
{
InitializeComponent();
}
//Code that get called when the page is navigated to
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
_textItems = new List<string>();
//Add ten items to text list to display
for (int i = 0; i < 10; i++)
{
_textItems.Add("Item" + i.ToString());
}
//For the default, set to first position and display it
_displayIndex = 0;
tblkDisplay.Text = _textItems[_displayIndex];
}
//If not at the first position of the list decrement by one, otherwise move to end of the list
private void Back()
{
if (_displayIndex > 0)
{
_displayIndex--;
}
else
{
_displayIndex = _textItems.Count - 1;
}
}
//If not at the last position of the list increment by one, otherwise move to start of the list
private void Forward()
{
if (_displayIndex < _textItems.Count - 1)
{
_displayIndex++;
}
else
{
_displayIndex = 0;
}
}
private void ShowText()
{
if ((_textItems.Count > 0) //Make sure there are items in the collection to display
&& (_displayIndex < _textItems.Count) // Make sure the index is not higher than how many items in the collection
&& (_displayIndex >= 0)) //Make sure the index is zero or greater
{
tblkDisplay.Text = _textItems[_displayIndex];
}
else
{
tblkDisplay.Text = "No Items.";
}
}
private void btnBack_Click(object sender, RoutedEventArgs e)
{
Back();
ShowText();
}
private void btnForward_Click(object sender, RoutedEventArgs e)
{
Forward();
ShowText();
}
Hello friends.
I am a lazy person with a lack of time. So, when I wanted to Phone Commander to add support for exporting registry keys to a file, I found an older, freely usable code (first I tried RegSaveKey coredll function, but I coud not elevate calling Process privilegies). PCMD will be the first "ondevice" WP7 application that allows you to export this (thanks Ultrashot we can also do it from a PC by Remote Tools). Unfortunately, the obtained code was using an MFC classes (CFile etc). Probably would not be a problem to rewrite it for another entry in the file, but I do not want change 3rd code. And MFC can be useful in the future too.
There were basically two options:
1. Use dynamic linking, because statically linking MFC to ATL is not allowed (conflicts of application instances). But then I had to get the correct library and try if they will run on WP7. In the future, I'll try.
2. Take all the MFC source code (included in WM DTK) and rewrite them to work statically in WP7, with prepared out CWinApp etc. It was a nasty job, but for some classes (especially CFile) is complete and functional to use. Next week there will publish libraries, source code and tutorial to use MFC classes in ATL native WP7 projects. EDIT: See 2nd post, this is probably better way then first one.
Meanwhile small code sample to export registers (ExportRegKey is 3rd function using CFile parameter):
Code:
BOOL ExportRegKey(HKEY hroot, const CString &root, const CString &key, CFile &out);
STDMETHODIMP CRegistryX::RegExportKeySimple(DWORD dwKey, LPCWSTR szSubKey, LPCWSTR szFileName)
{
TRACE(L"RegExportKeySimple(DWORD dwKey = %X, LPCWSTR szSubKey = %s, LPCWSTR szFileName = %s)", dwKey, szSubKey, szFileName);
try
{
HKEY hKey = (HKEY) dwKey;
LONG lRes = ERROR_SUCCESS;
CString root = L"";
switch (dwKey)
{
case HKEY_LOCAL_MACHINE:
{
root = _T("HKEY_LOCAL_MACHINE");
} break;
case HKEY_CURRENT_USER:
{
root = _T("HKEY_CURRENT_USER");
} break;
case HKEY_CLASSES_ROOT:
{
root = _T("HKEY_CLASSES_ROOT");
} break;
case HKEY_USERS:
{
root = _T("HKEY_USERS");
} break;
/*
case HKEY_CURRENT_CONFIG:
{
root = _T("HKEY_CURRENT_CONFIG");
} break;
*/
default:
{
root = _T("HKEY_UNKNOWN");
} break;
root = _T("");
}
CString key = szSubKey;
CFile out;
out.Open(szFileName, CFile::modeWrite | CFile::modeCreate );
lRes = ExportRegKey(hKey, root, key, out);
out.Close();
TRACE(L"RegExportKeySimple ExportRegKey lRes = %d)", lRes);
if (lRes == ERROR_SUCCESS)
{
return S_OK;
}
else
{
return ReturnError(L"RegSetDwordSimple RegSetValueEx", 0x80070000 | lRes);
}
}
catch (...)
{
return ReturnError(L"RegGetDwordSimple", GetLastError());
}
}
This is also Native TRACE example to see native messages in VP2010 managed Output window.
Full MFC using
I tried FULL MFC from VS2008 CE SDK using and this is possible.
1. Exe files - success with statical or dynamical MFC linking. Drawable components may have problems only.
2. Static linking to dll: If we can want use native dll with statically linked MFC to managed VS2010 dll or application, there are two ways:
- To change our usual COM interface to MFC standard. It may be possible, but I did not try it.
- To make ATL interstitial ATL dll with COM interface, which can call exported functions from MFC dll.
3. Dynamical MFC linking to ATL (COM) dll. I mean thi is the best way now.
For dynamical linking MFC dlls must be copied to device - to appplication directory or ideally to \Windows directory. Mostly:
\\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\dll\ARMV4I\msvcr90.dll
\\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\dll\ARMV4I\atl90.dll
\\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\dll\ARMV4I\msvcr90d.dll
\\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\dll\ARMV4I\MFC90UD.dll
Hello all,
Just curious about some general knowledge (salute; reference: HIMYM) on whether or not it's possible to see what an app is doing (during installation, in the background, app initialization, and foreground usage)
It's not my own app in question so I understand physically seeing the code is out of the question; however I'm more concerned about what the app is doing and the files/directories it accesses, and whether or not there's a way for me to view these activities.
If you must know, the app in question is the Adidas Confirmed app as RootCloak (and various other apps) DO NOT WORK. I'm attempting to isolate the issue, and I'm fairly certain it has to do with an external resource (within the device; i.e. different partition, files, folders, etc.) that permanently marks the device 'rooted' during initial installation. Maybe if I can see exactly what the app reaches out to, I can then come up with a fix action.
Any input would be greatly appreciated.
You could try to decompile this app, but it might not work very well if the app obfuscates the code http://decompileandroid.com/
Rijul.A said:
You could try to decompile this app, but it might not work very well if the app obfuscates the code http://decompileandroid.com/
Click to expand...
Click to collapse
This actually worked PERFECTLY. I was able to go inside the src and see exactly the commands the app calls for to check root.
If anyone is interested...I'm going to try a few things out, play with some variables and see if I can't allow the app access on my rooted device.
Code:
// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: braces fieldsfirst space lnc
package com.gpshopper.adidas.objects;
import android.os.Build;
import java.io.File;
// Referenced classes of package com.gpshopper.adidas.objects:
// ExecShell
public class Root
{
private static String LOG_TAG = com/gpshopper/adidas/objects/Root.getName();
public Root()
{
}
public static boolean checkRootMethod1()
{
String s = Build.TAGS;
return s != null && s.contains("test-keys");
}
public static boolean checkRootMethod2()
{
label0:
{
label1:
{
boolean flag = false;
boolean flag1;
try
{
File file = new File("/system/app/Superuser.apk");
File file1 = new File("/system/app/SuperSU/SuperSU.apk");
if (file.exists())
{
break label1;
}
flag1 = file1.exists();
}
catch (Exception exception)
{
return false;
}
if (!flag1)
{
break label0;
}
}
flag = true;
}
return flag;
}
public static boolean checkRootMethod3()
{
return (new ExecShell()).executeCommand(ExecShell.SHELL_CMD.check_su_binary) != null;
}
public static boolean isDeviceRooted()
{
return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
}
}
There is a similar file also in the src using a different language I've not yet been able to comprehend. I'm really new at this in case you couldn't already figure lol...is it possible to view my device's database where apps store variables? It may be possible the app is permanently storing the variable even after its removal so best case would be to start from a fresh ROM install. Just a theory.
The other language is generally irrelevant
Delete /data/data/<packagename>/ or clear app data normally, that will work, no need for a fresh install.
If you need help hooking this method, please quote me in a reply.