mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 01:25:50 +01:00
Display app name, company and version when opening a .pbw file from a filemanager
This commit is contained in:
parent
d4ff94da4a
commit
4117444c26
@ -8,6 +8,7 @@
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES" />
|
||||
|
||||
<application
|
||||
@ -33,11 +34,26 @@
|
||||
|
||||
<activity
|
||||
android:name=".AppManagerActivity"
|
||||
android:label="App Manager">
|
||||
android:label="@string/title_activity_appmanager">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ControlCenter" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AppInstallerActivity"
|
||||
android:label="@string/title_activity_appinstaller">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".AppManagerActivity" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:host="*" />
|
||||
<data android:scheme="file" />
|
||||
<data android:pathPattern=".*\\.pbw" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".NotificationListener"
|
||||
|
@ -0,0 +1,98 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
||||
public class AppInstallerActivity extends Activity {
|
||||
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
|
||||
TextView debugTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_appinstaller);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
debugTextView = (TextView) findViewById(R.id.debugTextView);
|
||||
debugTextView.setText("contents:\n");
|
||||
Uri uri = getIntent().getData();
|
||||
|
||||
ContentResolver cr = getContentResolver();
|
||||
InputStream fin = null;
|
||||
try {
|
||||
fin = cr.openInputStream(uri);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
ZipInputStream zis = new ZipInputStream(fin);
|
||||
ZipEntry ze = null;
|
||||
GBDeviceApp app;
|
||||
try {
|
||||
while ((ze = zis.getNextEntry()) != null) {
|
||||
if (ze.getName().equals("appinfo.json")) {
|
||||
long bytes = ze.getSize();
|
||||
if (bytes > 8192) // that should be too much
|
||||
break;
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int count;
|
||||
while ((count = zis.read(buffer)) != -1) {
|
||||
baos.write(buffer, 0, count);
|
||||
}
|
||||
|
||||
String jsonString = baos.toString();
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonString);
|
||||
String appName = json.getString("shortName");
|
||||
String appCreator = json.getString("companyName");
|
||||
String appVersion = json.getString("versionLabel");
|
||||
if (appName != null && appCreator != null && appVersion != null) {
|
||||
debugTextView.setText("This is just a test, you cant install anything yet \n\n" + appName + " Version " + appVersion + " by " + appCreator + "\n");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
zis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
NavUtils.navigateUpFromSameTask(this);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
@ -61,8 +61,7 @@ public class ControlCenter extends Activity {
|
||||
mGBDeviceAdapter.notifyDataSetChanged();
|
||||
if (state == GBDevice.State.CONNECTED) {
|
||||
hintTextView.setText("tap connected device for App Mananger");
|
||||
}
|
||||
else if (state == GBDevice.State.NOT_CONNECTED ) {
|
||||
} else if (state == GBDevice.State.NOT_CONNECTED) {
|
||||
hintTextView.setText("tap a device to connect");
|
||||
}
|
||||
break;
|
||||
@ -77,7 +76,7 @@ public class ControlCenter extends Activity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_controlcenter);
|
||||
hintTextView = (TextView) findViewById(R.id.hintTextView);
|
||||
hintTextView = (TextView) findViewById(R.id.hintTextView);
|
||||
deviceListView = (ListView) findViewById(R.id.deviceListView);
|
||||
mGBDeviceAdapter = new GBDeviceAdapter(this, deviceList);
|
||||
deviceListView.setAdapter(this.mGBDeviceAdapter);
|
||||
|
16
app/src/main/res/layout/activity_appinstaller.xml
Normal file
16
app/src/main/res/layout/activity_appinstaller.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.AppInstallerActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/debugTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
@ -14,6 +14,9 @@
|
||||
<string name="title_activity_appmanager">App Manager</string>
|
||||
<string name="appmananger_app_delete">Delete</string>
|
||||
|
||||
<!-- Strings related to AppInstaller -->
|
||||
<string name="title_activity_appinstaller">App Installer</string>
|
||||
|
||||
<!-- Strings related to Settings -->
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
<string name="pref_header_general">General Settings</string>
|
||||
|
Loading…
Reference in New Issue
Block a user