How do i get the current connected WiFi SSID / Name?
Please give me a snipplet.
EDIT:
WifiManager wifiMgr = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String name = wifiInfo.getSSID();
Somthing like that, but it shows me error at getActivity()..
EDIT2:
Got it work ->
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String info = wifi.getConnectionInfo().getSSID();
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
in the manifest
Related
Hi, I was wondering if you could help me with a problem Im having with widget-development for WM6.5.
I have a simple html-page using an XMLHttpRequest to read a string from local textfile (ie. placed in the same folder)
To verify that the string has been read, it is printed using a innerHTML-call.
main.htm
Code:
<html> <head>
<script type="text/JavaScript">
<!--
var htmlFileContent = new XMLHttpRequest();
function GetHTMLContent(htmlFileName){
htmlFileContent.open("GET", htmlFileName, true);
htmlFileContent.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
htmlFileContent.onreadystatechange = function()
{
if (htmlFileContent.readyState == 4)
{
document.getElementById('change').innerHTML = htmlFileContent.responseText;
}
}
htmlFileContent.send(null);
}
//-->
</script>
</head>
<body>
<div id="change">Orginal text</div>
<BUTTON type="button" name="mybutton2" onClick="GetHTMLContent('resource.txt');">Change text</BUTTON>
</body> </html>
resource.txt
Code:
Text has been changed
This works fine in for instance Opera (on the desktop), but not at all in IE8 (using standard settings).
Trying it on devices also gives an ambigous result. On Nokia's devices, packaging it as a WTR-widget, it works fine, but on the WM6.5 emulator it does not.
This leads me to believe that it has something to do with XMLHttpRequest-restrictions for certain browsers/devices.
The config.xml is packaged in the same folder:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<widget version="1.0" xmlns="http://www.w3.org/ns/widgets" id="">
<name>Test</name>
<content src="main.htm" type="text/html" />
<access network="true" />
<icon src="icon.png"/>
<description>Testapp</description>
</widget>
Any ideas as to what I can do/what the problem is?
Thanks,
Daniel
Hi, I am new in xda-developers forum. I have written my first simple application which uses GPS. Now I want to use Google Maps. Is problem because it want apiKey. My apiKey is in Google Code Api's Console. There is Android apps:
8A5:....:72:88:AE;com.borneq.heregpslocation and ApiKey : AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM (it is public or private?)
I modified three file to do with maps:
* AndroidManifest.xml:
Code:
<permission
android:name="com.borneq.heregpslocation.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.borneq.heregpslocation.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Code:
<uses-library android:name="com.google.android.maps" />
Code:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM" />
Second file is activity_main.xml :
Code:
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM"
android:clickable="true" />
Third is .MainActivity.java :
import com.google.android.maps.MapActivity;
public class MainActivity extends MapActivity implements OnClickListener {
Click to expand...
Click to collapse
Previously used controls I commnted
Project compiles but application breaks at start. I attach source: zipped program and logCat
Thanks!
The app crashs in line 77 of MainActivity. It's a NullPointerException.
Code:
boolean isGps = locationManager.isProviderEnabled("gps");
The reason for the crash is that in onCreate you commented this line out:
Code:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Due to this the variable locationManager is null and it crashes later because it cannot handle a null value. Just uncomment the line from onCreate which I pasted above. That's it.
How did I know that? It's in the logcat:
Code:
Caused by: java.lang.[B]NullPointerException[/B]
at com.borneq.heregpslocation.MainActivity.setButtonState([B]MainActivity.java:77[/B])
This guide might help you understand logcats (focus on that part of the guide): [GUIDE] Debugging apps You'll definitely need that knowledge if you want to do serious Android development. The earlier you learn it the better. Good luck.
nikwen said:
The app crashs in line 77 of MainActivity. It's a NullPointerException.
Code:
boolean isGps = locationManager.isProviderEnabled("gps");
The reason for the crash is that in onCreate you commented this line out:
Code:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Click to expand...
Click to collapse
Thanks, I remove by comment old controls and not noticed that comment also locationManager (!)
I correct; removed reference to commented controls and I don't have error but I can't see maps
Is "class MainActivity extends MapActivity" but np map, only lattice
I'm implementing app indexing and I think I'm missing something, but I don't know what.
Following the guide I added my intent-filters to the app and implemented what's needed in my activity.
my application's package is com.towers.mypackage and the associated website (where I didn't put the link rel meta-tag yet, since I'm just testing) is www.mypackage.com
I saw the following intent-filter example in the guide
HTML:
<activity
android:name="com.example.android.PetstoreActivity"
android:label="@string/title_petstore">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.examplepetstore.com" />
</intent-filter>
</activity>
so I wrote mine in this way:
HTML:
<activity
android:name=".ActivityForAppIndexing"
android:label="@string/title_activity"
android:screenOrientation="portrait" >
<intent-filter android:label="@string/app_name">
<data android:scheme="android-app"
android:host="com.package.myappname" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="www.mywebsite.com" />
<data android:scheme="https"
android:host="www.mywebsite.com" />
</intent-filter>
</activity>
Also, I wrote a content provider in order to parse the URI
HTML:
<provider
android:name=".contentproviders.HotelDetailsContentProvider"
android:authorities="com.towers.mypackage" >
</provider>
which should map the URIs as follows:
Code:
private static final String BASE_PATH = "https";
private static final String AUTHORITY = "com.towers.mypackage";
public static final Uri CONTENT_URI = Uri.parse("android-app://" + AUTHORITY
+ "/" + BASE_PATH);
I'm testing the implementation via command line using the following adb command:
Code:
adb shell am start -a android.intent.action.VIEW -d "https://mypackage.com?hotel_id=135738" com.towers.mypackage
and IT WORKS. The app gets automatically opened with the right activity and the right parameters. When the app starts the onNewIntent method gets called:
Code:
protected void onNewIntent(Intent intent) {
String action = intent.getAction();
String data = intent.getDataString();
if (Intent.ACTION_VIEW.equals(action) && data != null) {
String recipeId = data.substring(data.lastIndexOf("/") + 1);
Uri contentUri = HotelDetailsContentProvider.CONTENT_URI.buildUpon()
.appendPath(recipeId).build();
bundle = new Bundle();
bundle.putString("pictureUrl", "");
//showRecipe(contentUri);
}
}
(I got it of course from the examples, that's why it talks about recipes)
But I wonder: what should I do? Get data from the intent with a
Code:
getIntent().getData().getQuery()
or use the ContentProvider and get them from the URI?
Also, I'd like to test with the Google Search Console and the "View as google" funcionality if everything is okay. I uploaded my APK and saw an URI is requested.
Now, in the "testing your app" section of the documentation I saw that the links like http://mypackage.com?hotel_id=135738 are referred as "deep links" while those like android-app://com.towers.mypackage/https/mypackage.com?hotel_id=135738 are referred as "URI". Am I right?
The "View as google" funcionality asks for a URI but I don't know how to create one. Also, I wonder how this URI is passed to the app and I'm pretty sure I'm getting very confused about this all URI/deepLink thing, and can't find relief in the documentation.
Where and when should I use the URI? Where and when should I use the deepLink? I guess that since I'm going to put the link rel=URI in my webpages then the app will be called in the app indexing with the URI and not with the URL of the page. But if it's so... why is the adb shell am start -a android.intent.action.VIEW -d command used for testing with the URL and not the URI? Should my app be able to get and handle URIs or URLs? And how?
I thought I had understood something about app indexing, but today I'm starting to think I got it all wrong since I started. That's why I ask you for help in answering the questions above, and possibly sheding a light on all this URL/URI/intent-filter/ContentProvider mess.
I already talked about this on Stackoverflow and got two answers, plus a lot of comments. But I wasn't able to get anything from that, App indexing remains a mysterious monster to me :-/
Did anyone of you manage to make this kind of things work? And how?
Thank you everybody, really.
Hallo,
i want to add a new Contact in Android 6.0 but i get a permission problem and i dont now why.
This is my code:
Code:
Context cntx = getApplicationContext();
WritePhoneContact("John", "9999999999", cntx);
public void WritePhoneContact(String displayName, String number,Context cntx /*App or Activity Ctx*/)
{
Context contetx = cntx; //Application's context or Activity's context
String strDisplayName = displayName; // Name of the Person to add
String strNumber = number; //number of the person to add with the Contact
ArrayList<ContentProviderOperation> cntProOper = new ArrayList<ContentProviderOperation>();
int contactIndex = cntProOper.size();//ContactSize
//Newly Inserted contact
// A raw contact will be inserted ContactsContract.RawContacts table in contacts database.
cntProOper.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)//Step1
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null).build());
//Display name will be inserted in ContactsContract.Data table
cntProOper.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)//Step2
.withValueBackReference(Data.RAW_CONTACT_ID,contactIndex)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, strDisplayName) // Name of the contact
.build());
//Mobile number will be inserted in ContactsContract.Data table
cntProOper.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)//Step 3
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,contactIndex)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, strNumber) // Number to be added
.withValue(Phone.TYPE, Phone.TYPE_MOBILE).build()); //Type like HOME, MOBILE etc
try
{
// We will do batch operation to insert all above data
//Contains the output of the app of a ContentProviderOperation.
//It is sure to have exactly one of uri or count set
ContentProviderResult[] contentProresult = null;
contentProresult = contetx.getContentResolver().applyBatch(ContactsContract.AUTHORITY, cntProOper); //apply above data insertion into contacts list
}
catch (RemoteException exp)
{
//logs;
}
catch (OperationApplicationException exp)
{
//logs
}
}
Permission at the Manifest
Code:
<uses-spermission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Error Messge: Permission Denial: writing com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/raw_contacts from pid=32347, uid=10240 requires android.permission.WRITE_CONTACTS, or grantUriPermission()
Thank you for help
Uses-Spermission?
ageofempires said:
..... Error Messge: Permission Denial ....
Click to expand...
Click to collapse
I've had the same errors.
Don't know why.
Thoughts: Sync program on my PC is interfering when syncing Contacts and Agenda with Outlook.
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
I Hope it helped!
Hello,
first of all, english is not my foreign language, but I hope you understand:
I made an app (only WebView) for opening a website. I want to make the app for offline-using. So I used getSettings().setAppCachePath() and getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY).
When I open a page connected to Wifi it works. But open the same page again it doesn't work and it's only shown: ERR_CACHE_MISS
What is wrong?
Here is my code:
Code:
public WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tischtennis);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.setWebViewClient(new MyAppWebViewClient());
// Enable Javascript
mWebView.getSettings().setJavaScriptEnabled(true);
// Cookies
CookieManager.getInstance().setAcceptCookie(true);
// CookieManager.getInstance().setAcceptThirdPartyCookies(true);
// Caching
mWebView.getSettings().setAppCacheMaxSize(1024*1024*10);
String cacheDir = getApplicationContext().getCacheDir().getAbsolutePath();
mWebView.getSettings().setAppCachePath(cacheDir);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
// Offline Support
if ( isNetworkAvailable() ) {
mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
} else {
mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
}
mWebView.loadUrl("www........");
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(getApplicationContext().CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
And my Manifest-permissions:
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />